Re: [R] find mean of a list of timeseries

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Sat 14 Jan 2006 - 06:15:23 EST

Try:

(a+b+c)/3

On 1/13/06, tom wright <tom@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



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 06:22:22 2006

This archive was generated by hypermail 2.1.8 : Sat 14 Jan 2006 - 14:05:30 EST