How would you subset a time-series data.frame based on time and a threshold value?
I have this data:
year <- seq(2000, 2009, 1)
v1 <- sample(1:10, 10, replace=T)
df <- data.frame(year, v1)
That looks like this:
> df
year v1
1 2000 9
2 2001 4
3 2002 5
4 2003 4
5 2004 5
6 2005 3
7 2006 3
8 2007 3
9 2008 9
10 2009 6
I want to subset the data by groups of sequential years for which the summed score on v1
exceeds the value of 10.
On this example data the first subset should hold observations of the year 2000 & 2001. The second subset should hold the observations of year 2002, 2003 and 2004.
The real data has about 8 million observations covering 120 years.
set.seed
when create examples usingsample
– David Arenburg