[R] how does R represent numbers?
Prof Brian Ripley
ripley at stats.ox.ac.uk
Thu Sep 13 15:55:28 CEST 2001
On Thu, 13 Sep 2001, Bill Simpson wrote:
> 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)
> [1] FALSE
All as documented in ?seq.
> The vector is double if I do it like this:
> > a<-c(1,2,3)
> > is.integer(a)
> [1] FALSE
>
> rep() seems to make doubles:
> > a<-rep(1,3)
> > is.integer(a)
> [1] FALSE
>
> A single number with no decimal place is double:
> > is.integer(1)
> [1] FALSE
> 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() *
There are good reasons for this, the main one being that systems
should work as advertised.
There are other sorts of numbers in R too, BTW. (Hint: what are the five
atomic vector types?)
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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