R - Subsetting XTS via Time and Which
Posted
by
user2844947
on Stack Overflow
See other posts from Stack Overflow
or by user2844947
Published on 2014-05-27T15:21:54Z
Indexed on
2014/05/27
15:24 UTC
Read the original article
Hit count: 165
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.
© Stack Overflow or respective owner