[R] bug in rle?
Prof Brian Ripley
ripley at stats.ox.ac.uk
Wed Jan 8 17:53:16 CET 2014
On 08/01/2014 16:23, Bert Gunter wrote:
> Is the following a bug?
> ##(R version 3.0.2 (2013-09-25)
> ## Platform: i386-w64-mingw32/i386 (32-bit))
>
>
> d <- data.frame(a=rep(letters[1:3],4:6))
> rle(d$a)
> ##Error in rle(d$a) : 'x' must be an atomic vector
>
> is.atomic(d$a)
> ##[1] TRUE
But
> is.vector(d$a)
[1] FALSE
The discrepancies in what a 'vector' is in R are very long standing, but
a factor is not a vector.
> rle(c(d$a))
That loses the class and other attributes, giving a vector.
> ## Run Length Encoding
> ## lengths: int [1:3] 4 5 6
> ## values : int [1:3] 1 2 3
>
> Cheers,
> Bert
>
> Bert Gunter
> Genentech Nonclinical Biostatistics
> (650) 467-7374
--
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 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list