dinman
dinman

Reputation: 55

How do I combine many zoo objects in R

I have > 100 zoo objects that I would like to combine (cbind) into one large zoo object. The zoo objects are stored in my working directory. I have created a list of the file names (with pathway information) and am trying to use this list in do.call to perform cbind.

path <- "~/mydata/"

files <- as.list(list.files(path=path, pattern= "*.RData", full.names=TRUE))

big.zoo<-do.call(cbind,files)

When I run the above code, it cbinds just the file names and their pathways. The zoo files are not combined.

Does anyone have any suggestions?

Upvotes: 0

Views: 383

Answers (1)

won782
won782

Reputation: 721

n = length(files)
big.zoo = NULL
for (i in 1:n) {
  temp = load(file[i])
  big.zoo = merge(big.zoo, temp)
}

Since I do not have your data, I cannot be sure if this will work, but if your RData is a zoo object, and all of your file name list has been loaded properly to 'files', this should work.

Upvotes: 1

Related Questions