Skip to content
Prev 166988 / 398502 Next

help

Be careful there if the original data contains negative numbers.

As per ?floor:

takes a single numeric argument x and returns a numeric vector
containing the largest integers not greater than the corresponding
elements of x.

Thus:

x <- seq(-2, 2, 0.25)
[1] -2.00 -1.75 -1.50 -1.25 -1.00 -0.75 -0.50 -0.25  0.00  0.25  0.50
[12]  0.75  1.00  1.25  1.50  1.75  2.00
[1] -2 -2 -2 -2 -1 -1 -1 -1  0  0  0  0  1  1  1  1  2


Compare that with using trunc():

takes a single numeric argument x and returns a numeric vector
containing the integers formed by truncating the values in x toward 0.
[1] -2 -1 -1 -1 -1  0  0  0  0  0  0  0  1  1  1  1  2


Note that each returns a numeric (not integer) data type, albeit rounded
to the appropriate whole integer value. In R code, that is typically a
non-issue.

HTH,

Marc Schwartz
on 01/14/2009 08:55 AM Nutter, Benjamin wrote: