[R] R internal data types
Benjamin.STABLER@odot.state.or.us
Benjamin.STABLER at odot.state.or.us
Thu Jan 15 00:52:46 CET 2004
I am trying to figure out R data types and/or storage mode. For example:
> #From a clean workspace
> gc()
used (Mb) gc trigger (Mb)
Ncells 415227 11.1 597831 16
Vcells 103533 0.8 786432 6
> x <- seq(0,100000,1)
> is.integer(x)
[1] FALSE
> is.double(x)
[1] TRUE
> object.size(x)
[1] 800036
> gc()
used (Mb) gc trigger (Mb)
Ncells 415247 11.1 667722 17.9
Vcells 203543 1.6 786432 6.0
> x <- as.integer(x)
> is.integer(x)
[1] TRUE
> is.double(x)
[1] FALSE
> gc()
used (Mb) gc trigger (Mb)
Ncells 415249 11.1 741108 19.8
Vcells 153543 1.2 786432 6.0
> x <- 1:100000
> is.integer(x)
> gc()
used (Mb) gc trigger (Mb)
Ncells 415278 11.1 741108 19.8
Vcells 153553 1.2 786432 6.0
> is.integer(3)
[1] FALSE
> is.double(3)
[1] TRUE
> is.integer(3 * as.integer(5))
[1] FALSE
> is.integer(as.integer(3) * as.integer(5))
[1] TRUE
> is.integer(c(as.integer(5),as.integer(6),as.integer(7)))
[1] TRUE
> is.integer(c(as.integer(5),as.integer(6),7))
[1] FALSE
> is.integer(seq(as.integer(5),as.integer(10),1))
[1] FALSE
> is.integer(seq(as.integer(5),as.integer(10),as.integer(1)))
[1] TRUE
So it looks like R stores numbers as doubles unless the are converted to
integers (long) with the as.integer() function or they are created with the
: operator. If any of the numbers to a function are not type integer than
the function returns type double. Is this the case? Thanks.
Ben Stabler
Oregon Department of Transportation
More information about the R-help
mailing list