R: Average by every N value in 3-dim matrix -


i have matrix hourly data (on monthly period) , dim [116 152 744] trying create matrix b daily data , dim [116 152 31] every dim tstep in b average of first 24 tsteps in matrix a.

i successful in creating matrix c monthly data simple apply

c <- apply(a, c(1,2), function (x) mean(x)) 

but can't quite figure out average on every n values. thanks.

take 1 vector only, mean every 24 values, can do:

mean24 <- function(x) {   dim(x) <- c(24, length(x) / 24)   colmeans(x) }  x <- 1:48 mean24(x) [1] 12.5 36.5 

so, in case, have do:

apply(a, c(1, 2), mean24) 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -