[R] sample nth day data in each month
Emmanuel Charpentier
charpent at bacbuc.dyndns.org
Thu Nov 15 23:43:30 CET 2007
Carles Fan a écrit :
> Dear all
>
> i have a time series containing trading dates and historical stock prices:
> Date Price
> 10-Jan-2007 100
> 11-Jan-2007 101
> 13-Jan-2007 99
> ......
> ......
> ......
> 10-Nov-2007 200
>
> i want to sample every 21st data of each month:
> 21-Jan-2007 101
> 21-Feb-2007 111
> 21-Mar-2007 131
> ......
> ......
> ......
> 21-Oct-2007 140
>
> 1) how can i do that?
YourDataFrame[strptime(YourDataFrame$Date,"%Y-%b-%d")$mday==21,]
# beware your locale !
> 2) if some of the dates are non-trading day, how can i tell "R" to use
> "modified following" or "following" data?
Dunno : what is a"non-trading day" ?
HTH
Emmanuel Charpentier
More information about the R-help
mailing list