> -Original Message-
> From: r-help-boun...@r-project.org
> [mailto:r-help-boun...@r-project.org] On Behalf Of Henrique
> Dallazuanna
> Sent: Monday, September 14, 2009 9:59 AM
> To: smu
> Cc: r-help@r-project.org
> Subject: Re: [R] local sequence function
>
try the following:
v <- c(NA,NA,TRUE,TRUE,NA,TRUE,NA,TRUE,TRUE,TRUE)
l <- as.numeric(!is.na(v))
tmp <- cumsum(l)
tmp - cummax((!l) * tmp)
I hope it helps.
Best,
Dimitris
smu wrote:
hey,
I can not find a function for the following problem, hopefully you can
help me.
I have a vactor like t
Try this also:
with(rle(v), unlist(sapply(lengths, FUN = seq)) * v)
On Mon, Sep 14, 2009 at 12:20 PM, smu wrote:
> hey,
>
> I can not find a function for the following problem, hopefully you can
> help me.
>
> I have a vactor like this one
>
> v = c(NA,NA,TRUE,TRUE,NA,TRUE,NA,TRUE,TRUE,TRUE)
>
Try this:
v <- c(NA,NA,TRUE,TRUE,NA,TRUE,NA,TRUE,TRUE,TRUE)
ick <-rle(v)
foo <- unlist(apply(matrix(ick$lengths),1,seq))
foo[is.na(v)] <- NA
foo
[1] NA NA 1 2 NA 1 NA 1 2 3
-Don
At 5:20 PM +0200 9/14/09, smu wrote:
hey,
I can not find a function for the following problem, hopefu
> "s" == smu
> on Mon, 14 Sep 2009 17:20:27 +0200 writes:
s> hey, I can not find a function for the following problem,
s> hopefully you can help me.
s> I have a vactor like this one
s> v = c(NA,NA,TRUE,TRUE,NA,TRUE,NA,TRUE,TRUE,TRUE)
s> and I would like to the
5 matches
Mail list logo