I have around thirty separate time series in R. I would like to put them all inside one large data set but can not seem to do this.
I have used the following code but it doesn't work. All my time series are names ts1,ts2 etc. if i was to do df <- data.frame(ts1,ts2) this works individually but not if I input it this way
for(i in 2:nrow(deal))
temp <- paste("ts",i,sep="")
mystring <- paste(mystring,temp,sep=",")
df <- data.frame(mystring)
df <- data.frame(ts1,ts2) works, the following should work:
N <- nrow(deal) # or whatever number of time series you have df <- data.frame(sapply(1:N, function(i) eval(parse(text=paste("ts",i,sep="")))))
sapplyloops over sequence from
Nand applies a function. The results of the function are gathered as columns to a matrix that is then coerced into a data frame.
i-th time series and uses this SO answer to evaluate the expression from the string. This returns the time series.
Hope this helps.