在 R 编程中四舍五入到上限或下限 - trunc()函数
R 语言中的trunc()
函数用于返回小于或等于 x 的最大整数(即:向下舍入最接近的整数)。 trunc()函数表现为负数的上限函数和正数的下限函数。
Syntax: trunc(x)
Parameter:
x: Numeric value to be rounded off
示例 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
-3
示例 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