From Kurt.Hornik@ci.tuwien.ac.at  Sat Apr  7 16:07:29 2001
From: Kurt.Hornik@ci.tuwien.ac.at (Kurt Hornik)
Date: Sat, 7 Apr 2001 17:07:29 +0200
Subject: [Rd] rle() fails with NA's (PR#892)
In-Reply-To: <200104031952.VAA19642@pubhealth.ku.dk>
References: <200104031952.VAA19642@pubhealth.ku.dk>
Message-ID: <15055.11569.324300.836330@mithrandir.hornik.net>

>>>>> jhallman  writes:

> 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])
> }

Thanks for pointing out the problem.

I've committed a fix for 1.2.3, but I don't think that the Splus
implementation is right: when a sequence of NAs occurs, it is treated as
one value, which does not make too much sense to me.  The new R version
treats each NA separately.  (Could be changed of course to mimic the
Splus behavior.)

-k
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


[Rd] rle() fails with NA's (PR#892)
Kurt Hornik