Jul
31

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

Written by connygy. Posted in R

Trackback from your site.

Leave a comment