R - Subsetting XTS via Time and Which
- by user2844947
Currently, I have a XTS, called Data, which contains a Date, and two value columns which are numbers. I would like to get a single number as output and which would be the mean of Value1 in the time period from a point where Value2 < mean(Value2) and going forward 14 data points, weeks in this particular data set. In order to get the dates where Value2 < mean(Value2), I wrote the below code
Data[which(Data$Value2 < mean(Data$Value2)),"Date"]
However, I am not sure how to get the mean of Value1 in the period, going 14 days forward from each of the resultant dates from the above code.