[R] foreloop? aggregating time series data into groups

blurg ian.jhsph at gmail.com
Mon Nov 1 20:34:20 CET 2010


I have a data set similar to the set below where 1 and 2 indicate test
results and 0 indicates time points in between where there are no test
results.  I would like to allocate the time points leading up to a test
result with the value of the test result. 

What I have:     What I want:
1                     1
0                     1
0                     1
0                     1
1                     1
0                     2
0                     2
2                     2
0                     1
0                     1
1                     1
0                     2
2                     2

I have attempted methods creating a data.frame of the the breaks/changes in
of values to from 0 to 1 or to 2.
x<-c(0,2,0,1,0,0,0,0,1,0,1,0,0,0,2,1,0,0,0,2,0,0,0,1)
x1 <- which(diff(x) == 1) 
x2 <- which(diff(x) == 2)

What ever the solution, I can't be entered by hand due to the size of the
dataset (>10 million and change). Any ideas?  This is my first time posting
to this forum and I am relatively new to R, so please don't flame me to
hard.  Desperate times call for desperate measures.  Thanks.
-- 
View this message in context: http://r.789695.n4.nabble.com/foreloop-aggregating-time-series-data-into-groups-tp3022667p3022667.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list