[R] find mean of a list of timeseries

From: tom wright <tom_at_maladmin.com>
Date: Fri 13 Jan 2006 - 23:06:54 EST


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



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat Jan 14 04:05:59 2006

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:42:04 EST