Skip to content

Coversion from yearly to weekly data

3 messages · Nico Met, Rui Barradas, PIKAL Petr

#
Hello,

Something like this?


sp <- split(test, test$Data)
res <- do.call(rbind, lapply(sp, function(x){
	Week <- (seq_len(nrow(x)) %/% 7) + 1
	aggregate(Value ~ Data + Week, data = x, FUN = mean)}))
rownames(res) <- seq_len(nrow(res))
res


Hope this helps,

Rui Barradas

Em 08-03-2013 15:16, Nico Met escreveu:
#
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