[R] Merging zoo objects
ggrothendieck at gmail.com
Fri Jan 7 19:12:55 CET 2011
On Fri, Jan 7, 2011 at 1:01 PM, Pete B <Peter.Brecknock at bp.com> wrote:
> I have n zoo objects M1, M2, M3, ... , Mn that I want to merge where n is a
> number calculated at run-time.
> I am struggling to find the correct syntax to do this
> Assuming n is calculated as 10 (for example), I have tried
> n = 10
> # First Effort
> alldata= merge(paste("M",rep(1:n), sep=""),all=TRUE)
> # Second Effort
Try this where the sapply creates a list of the objects.
M1 <- zoo(11:13); M2 <- zoo(21:24); M3 <- zoo(31:35)
do.call("merge", sapply(ls(pattern = "^M"), get, simplify = FALSE))
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
email: ggrothendieck at gmail.com
More information about the R-help