[Rd] rle() fails with NA's (PR#892)
jhallman@frb.gov
jhallman@frb.gov
Tue, 3 Apr 2001 21:52:46 +0200 (MET DST)
Full_Name: Jeff Hallman
Version: 1.2.2
OS: Solaris
Submission from: (NULL) (132.200.32.33)
> rle(c(1, NA, 1)
$lengths
[1] 3
$values
[1] 1
should be as in Splus:
$lengths
[1] 1 1 1
$values
[1] 1 NA 1
The Splus implementation (which works fine in R) is:
rle <- function(x){
if(!is.atomic(x))
stop("Argument must have an atomic mode")
if(length(x) == 0)
return(list(lengths = numeric(0), values = x))
if(length(x) == 1)
return(list(lengths = 1, values = x))
x.int <- match(x, unique(x))
ends <- c(diff(x.int) != 0, T)
list(lengths = diff(c(0, seq(along = x)[ends])), values = x[ends])
}
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._