I have a loop that extracts ~200 individual timeseries by making calls to an API.
The loop outputs the timeseries as xts objects (library(xts)
) into the Global Environment with the suffix ".oc". So I have 200 xts objects of the form "ABC.oc", "ABD.oc" etc. Each object contains 1000 rows of data.
What I would like to do is write a loop (or use an appropriate function) that takes all the "*.oc" objects and merges them by column. IE would end up with:
Date ABC.oc ABD.oc -> 200 columns like this
2011-01-01 10 10
2011-01-02 20 20
2011-01-03 30 30
2011-01-04 40 40
2011-01-05 50 50
With a short list of timeseries, would just write:
m <- merge(ABC.oc,ABD.oc,all=FALSE)
But obviously this is not practical with 200 individual objects, so I'd like to write a loop to smash all these objects together like "merge" does.
Easy enough to access the variables for the loop via for i in length(ls(pattern="*.oc")){
but just cannot figure out the rest of the loop.
I've tried cbind, but can't seem to get it right.
Any help much appreciated