[R] replacing segments of vector by their averages

From: Daren Tan <daren76_at_hotmail.com>
Date: Thu, 19 Jun 2008 08:55:53 +0000

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.3, 2nd is 0.5, and the 3rd is 0.5333333  

> 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) [1] 0.30 0.30 0.30 0.10 0.10 0.50 0.50 0.50 0.50 0.15 0.15 0.30 0.50 0.80> m >= 0.2 [1] TRUE TRUE TRUE FALSE FALSE TRUE TRUE TRUE TRUE FALSE FALSE TRUE[13] TRUE TRUE
 


        [[alternative HTML version deleted]]



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu 19 Jun 2008 - 08:59:19 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 20 Jun 2008 - 13:30:47 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive