trunc() function in R Language is used to return the largest integer that is smaller than or equal to x (i.e : rounds downs the nearest integer). trunc() function behaves as a ceiling function for negative number and floor function for positive number.
Syntax: trunc(x) Parameter: x: Numeric value to be rounded offExample 1:
# R program to calculate trunc value
# Using trunc() method
answer1 <- trunc(3.4)
answer2 <- trunc(-3.4)
answer3 <- trunc(3.6)
answer4 <- trunc(-3.6)
print(answer1)
print(answer2)
print(answer3)
print(answer4)
3 -3 3 -3Example 2:
# R program to calculate trunc value
# Using trunc() method
answer1 <- trunc(c(1.5, 2.6, -3, -3.4))
print(answer1)
1 2 -3 -3