[R] help

Marc Schwartz marc_schwartz at comcast.net
Wed Jan 14 16:39:04 CET 2009


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)

> x
 [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


> floor(x)
 [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.

> trunc(x)
 [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:
> ?floor 
> 
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> On Behalf Of zahid khan
> Sent: Wednesday, January 14, 2009 8:34 AM
> To: r-help at stat.math.ethz.ch
> Subject: [R] help
> 
> Dear ALL
> suppose "x=7.5",and i need of only integer part of variable "x" that is
> "7" only then what command i can use in R.
> THANKS
>




More information about the R-help mailing list