[R] how does R represent numbers?

Bill Simpson wsi at gcal.ac.uk
Thu Sep 13 14:53:09 CEST 2001

I just found out that R assumes that vectors created with the : operator
are integer:
> a<-1:3
> is.integer(a)
[1] TRUE

Vectors created with seq() can be integer
> a<-seq(1,3)
> is.integer(a)
[1] TRUE

or double
> a<-seq(1,3,1)
> is.integer(a)

The vector is double if I do it like this:
> a<-c(1,2,3)
> is.integer(a)

rep() seems to make doubles:
> a<-rep(1,3)
> is.integer(a)

A single number with no decimal place is double:
> is.integer(1)
This is the reason I previously thought all numbers were double in R.

Maybe there's a good reason for this situation, but it seems strange and
inconsistent to me.

This might be a silly suggestion, but how about:
* all numbers assumed to be double unless explicitly set as integer *
* using integer() or changed to integer using as.integer()          *


r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list