Thanks a lot, it works very well!
Inti
2012/8/21 Rui Barradas
> Hello,
>
> Try the following
>
>
> d <- read.table(text="
>
> id VI
> 1 -10
> 2 -4
> 3 5
> 4 -2
> 5 -5
> 6 -3
> 7 -2
> 8 -1
> 9 4
> 10 8
> ", header = TRUE)
>
>
> fun <- function(n, thres){
> r <- rle(!d$VI < thres)
> in
Rui:
It's much simpler than you propose, which is why I left it to the OP.
Just use the results of rle to create a logical vector to index id.
For example, the solution for the OP's example becomes : (d is the
data frame containing id and VI)
> with(d,{
+ z <- rle(VI < 1)
+ vals <- with(z,values
Hello,
Try the following
d <- read.table(text="
id VI
1 -10
2 -4
3 5
4 -2
5 -5
6 -3
7 -2
8 -1
9 4
10 8
", header = TRUE)
fun <- function(n, thres){
r <- rle(!d$VI < thres)
inx <- which(!r$values & r$lengths >= n)
csum <- cumsum(r$lengths)
from <- ifelse(inx == 1, 1, csum[in
z <- rle(VI<1)
gets you most of the way there. ?rle will tell you what z is so that
you can then use it to go the rest of the way.
-- Bert
On Tue, Aug 21, 2012 at 10:54 AM, inti luna wrote:
> Hello,
>
> I have 2 variable: one is an "id" sequence from 1:1000 and the other is
> variable with real
4 matches
Mail list logo