The zoo package as a merge function which merges a set of zoo objects
result<-merge(zoo1,zoo2,...)

Assume your zoo objects are already collected in a list

# make a phony list to illustrate the situation. ( hat tip to david W for
constructing a list in a loop)

ddat <- as.list(rep("", 20))
 ytd<-seq(3,14)
 for(i in 1:20) {
+ ddat[[i]] <- zoo(data,ytd )
+ }


ddat
[[1]]
 1  2  3  4  5  6  7  8  9 10 11 12
 3  4  5  6  7  8  9 10 11 12 13 14

[[2]]
 1  2  3  4  5  6  7  8  9 10 11 12
 3  4  5  6  7  8  9 10 11 12 13 14

[[3]]
 1  2  3  4  5  6  7  8  9 10 11 12
 3  4  5  6  7  8  9 10 11 12 13 14

........

So given a list of zoo objects, if you want to create a merged  zoo object
is there a way to do that.

For example, merging the first two gives you this

result<-merge(ddat[[1]],ddat[[2]])
> result
   ddat[[1]] ddat[[2]]
3          3         3
4          4         4
5          5         5
6          6         6
7          7         7
8          8         8
9          9         9
10        10        10
11        11        11
12        12        12
13        13        13
14        14        14

And..

result<-merge(result,ddat[[3]])
> result
   ddat[[1]] ddat[[2]] ddat[[3]]
3          3         3         3
4          4         4         4
5          5         5         5
6          6         6         6
7          7         7         7
8          8         8         8
9          9         9         9
10        10        10        10
11        11        11        11
12        12        12        12
13        13        13        13
14        14        14        14

I'm thinking that either do.call or lapply should do the trick.. or a
combination of the two. It would appear to be a straightforward
recursion applying merge to the result of merge..the looping solution is
straightforward

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to