[R] A question about is.interger function
    Dieter Menne 
    dieter.menne at menne-biomed.de
       
    Wed Apr 26 08:32:26 CEST 2006
    
    
  
Leon <amstat2006 <at> gmail.com> writes:
> 
> Hi, All
> I am using is.integer function to examine whether an object is an integer or 
not, but I get such results,
> 
> > x<-3
> > is.integer(x)
> [1] FALSE
x <- 3
typeof(3)
[1] "double"
This may not be a wise decision in hindsight, but probably was made to avoid 
conversion when in the next step you do
x[2] = 1.5
y <- as.integer(3)
 typeof(y)
[1] "integer"
 
> > x<-3:4
> > x
> [1] 3 4
> > is.integer(x)
> [1] TRUE
Here R seems to know that 3 is an integer, which I believe is a bit 
inconsistent, but wise, because mostly you use integers here. Mostly; because 
1.5:3.5 
gives a reasonable result
[1] 1.5 2.5 3.5
Dieter
    
    
More information about the R-help
mailing list