[R] finding weekly average...

Daniel Malter daniel at umd.edu
Wed Apr 7 18:24:23 CEST 2010


Assume you have suitable "week" indicator and your data is stored in a
data.frame named "data." Then you get the weekly averages by

#simulate data
week <- rep(1:52,each=7)
x <- week+rnorm(52*7,)
y  <- rev(week)+rnorm(52*7)

#create data frame
data=data.frame(week,x,y)

#get weekly averages in a list
averages=unlist(lapply(split(data,week),colMeans))

#unlist averages and store the results in matrix
matrix(averages,byrow=T,ncol=dim(data)[2])

HTH,
Daniel
-- 
View this message in context: http://n4.nabble.com/finding-weekly-average-tp1754518p1754604.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list