[R] cut with infinite values -> NA (PR#1694)
ripley@stats.ox.ac.uk
ripley@stats.ox.ac.uk
Thu, 20 Jun 2002 14:05:00 +0200 (MET DST)
You are correct in your expectations. This is a bug: the C code does not
cover the cases +/-Inf (because it uses R_FINITE to exclude them).
I'll fix it in R-patched: filing with R-bugs for the record.
On 20 Jun 2002, Markus [ISO-8859-1] Jäntti wrote:
> 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.]
>
> Regards,
>
> Markus
> code:
>
> cut.off <- c(-Inf, 0, Inf)
> x <- c(-Inf, -10, 0, 10, Inf)
> is.numeric(x)
> is.double(x)
> # but
> cut(x, cut.off, include.lowest=T)
>
> > R.version
> _
> platform i386-pc-linux-gnu
> arch i386
> os linux-gnu
> system i386, linux-gnu
> status
> major 1
> minor 5.1
> year 2002
> month 06
> day 17
> language R
>
> --
> Markus Jantti
> Statistics Finland and University of Tampere
> markus.jantti@iki.fi
> http://www.iki.fi/~mjantti
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> 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@stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>
--
Brian D. Ripley, ripley@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-devel 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-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._