[R-SIG-Finance] Selecting once a month from a xts series

Brian G. Peterson brian at braverock.com
Thu Mar 25 02:18:49 CET 2010


Worik Stanton wrote:
> With a xts series of daily prices I want to select samples from once a month.
> 
> Given that p.xts is the xts series
> 
>> p.xts[1,]
>            Adj.Close
> 2003-01-01       4.3
> 
>> p.xts[length(p.xts[,1]),]
>            Adj.Close
> 2010-03-05      2.25
> 
> 
> 
> What I would like to do is...
> 
>> i <- seq(from=index(p.xts[1,]), to=index(p.xts[length(p.xts[,1]),]), by="month")
>> m.xts <- p.xts[i,]
> Error in `[.xts`(p.xts, i, ) : i is out of range
> 
> Of course some of the dates in 'i' are not in index(p  .xts)
> 
> Is there a simple solution?

?endpoints


-- 
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock



More information about the R-SIG-Finance mailing list