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

Worik Stanton worik.stanton at gmail.com
Thu Mar 25 02:06:40 CET 2010


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?

cheers
Worik

-- 
Dig it out of the ground
Melt it down
Bury it
Guard it



More information about the R-SIG-Finance mailing list