[R] Why is 0 not an integer?

Gerlanc, Daniel Daniel.Gerlanc at geodecapital.com
Thu Aug 6 23:00:12 CEST 2009


b/c
> class(0)
[1] "numeric"

> typeof(0)
[1] "double"

> class(0L)
[1] "integer"

> typeof(0L)
[1] "integer"

When you call the ":" function it always returns an integer sequence,
but when you assign a numeric to an element of the vector it gets
coerced to the more general type, in this case, numeric.

Note that "is.numeric" returns TRUE for both is.numeric(0) and
is.numeric(0L).

 

Daniel Gerlanc
Associate Analyst
Geode Capital Management
1 Post Office Sq, Floor 28
Boston, MA 02109
Daniel.Gerlanc at geodecapital.com




More information about the R-help mailing list