Does this give you the results you are expecting:
> m <- c(0.3,0.3,0.3,0.1,0.1,0.5,0.5,0.5,0.5,0.15,0.15,0.3,0.5,0.8)
> m > 0.2
[1] TRUE TRUE TRUE FALSE FALSE TRUE TRUE TRUE TRUE FALSE FALSE
TRUE TRUE TRUE
> m.rle <- rle(m > 0.2)
> offsets <- 1 + c(0, head(cumsum(m.rle$lengths), -1))
>
Given a vector of numeric of length n, I need to find segments that are >= 0.2,
compute the average of individual segments, and replace the original values in
each segment by their corresponding averages.
For example, there are three segments that are >= 0.2, the average of 1st
segment is 0.
2 matches
Mail list logo