[R] find mean of a list of timeseries

tom wright tom at maladmin.com
Fri Jan 13 13:06:54 CET 2006


Can someone please give me a clue how to 're'write this so I dont need
to use loops.

a<-ts(matrix(c(1,1,1,10,10,10,20,20,20),nrow=3),names=c('var1','var2','var3'))
b<-ts(matrix(c(2,2,2,11,11,11,21,21,21),nrow=3),names=c('var1','var2','var3'))
c<-ts(matrix(c(3,3,3,12,12,12,22,22,22),nrow=3),names=c('var1','var2','var3'))

data<-list(a,b,c)

I now want to find the means of all vectors var1,var2 and var3

i.e. I need to end up with a new time series with three data vectors
(var1, var2 and var3)
result<-ts(matrix(c(2,2,2,11,11,11,21,21,21),nrow=3),names=c('var1','var2','var3))

I think its the list thats throwing my use of apply, I might be wrong
but what other data structure could I use?

Many thanks
Tom




More information about the R-help mailing list