[R] cut with infinite values -> NA

Markus Jäntti markus.jantti at iki.fi
Thu Jun 20 13:30:52 CEST 2002

I am doing work on changes in establishment sizes and came across
behavior that is quite understandable and easily worked around but
a little surprising. On R 1.5.1 on Debian unstable (see below for
R.version output):

> cut.off <- c(-Inf, 0, Inf)
> x <- c(-Inf, -10, 0, 10, Inf)
> is.numeric(x)
[1] TRUE
> is.double(x)
[1] TRUE
> # but
> cut(x, cut.off, include.lowest=T)
[1] <NA>     [-Inf,0] [-Inf,0] (0,Inf]  <NA>   

The reason I am surprised is that standard logical operations on
Inf generate expected results and storage.mode(Inf) is double and
so on, so I was expecteing -Inf to belong to the lowest factor level and
Inf to belong the highest.

[For what it is worth, I am classifying establishments by their growth
across years and one that in t1 has 0 workers and >0 in the next
has infinite growth. This is easily worked around, but I am
a little curious.]



 cut.off <- c(-Inf, 0, Inf)
x <- c(-Inf, -10, 0, 10, Inf)
# but
cut(x, cut.off, include.lowest=T)

> R.version
platform i386-pc-linux-gnu
arch     i386             
os       linux-gnu        
system   i386, linux-gnu  
major    1                
minor    5.1              
year     2002             
month    06               
day      17               
language R       

Markus Jantti
Statistics Finland and University of Tampere
markus.jantti at iki.fi

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