Re: [R] replacing segments of vector by their averages

2008-06-20 Thread jim holtman
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)) #

[R] replacing segments of vector by their averages

2008-06-19 Thread Daren Tan
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