Skip to content
Prev 319071 / 398506 Next

Coversion from yearly to weekly data

Hi

some brute force

aggregate(test$Value, list(rep(1:61, each=7)[1:422]), mean)
or
aggregate(test$Value, list(findInterval(1:nrow(test), seq(1,422,by=7)), test$Data), mean)

gives you aggregated values for each week.

or
lll <- split(test, test$Data)
lapply(lll, function(x) aggregate(x, list(findInterval(1:nrow(x), seq(1,422,by=7))), mean)) 
if you want to separate SOIL and Air

However I am not sure how do you want those values to be organised.

Anyway, better approach is to change your Day to date variable by e.g. as.Date. The tricky way is to put correct month in

paste(month.vector, test$Day, 2012, sep=".")

Regards
Petr