[R] find mean of a list of timeseries

Gabor Grothendieck ggrothendieck at gmail.com
Fri Jan 13 20:15:23 CET 2006


Try:

(a+b+c)/3

On 1/13/06, tom wright <tom at maladmin.com> wrote:
> 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