trunc() and floor(), round() and signif() in R
floor takes a single numeric argument x and returns a numeric vector containing the largest integers not greater than the corresponding elements of x.
trunc takes a single numeric argument x and returns a numeric vector containing the integers formed by truncating the values in x toward 0.
round
rounds the values in its first argument to the specified number of decimal places (default 0).
signif
rounds the values in its first argument to the specified number of significant digits.
test:
————————–
> x <- c(-5.2, -3.8, 5.2, 3.8)
>floor(x)
-6 -4 5 3
>trunc(x)
-5 -3 5 3
> x <- 3.1415
—————————-
>round(x)
3
>round(x,3)
3.142
>signif(x,3)
3.14
452860 6068Nowhere on the Internet is there this much quality and clear information on this subject. How do I know? I know because Ive searched this topic at length. Thank you. 177614