Use kronecker products. For example,
> mat <- matrix(1001:1144, 12, 12)
> result <- k1 <- matrix(1:9, 3, 3)
> k2 <- matrix(1, 4, 4) # size of one block
> result[] <- tapply(mat, kronecker(k1, k2), mean)
> result
[,1] [,2] [,3]
[1,] 1020.5 1068.5 1116.5
[2,] 1024.5 1072.5 1120.5
[3,] 102
Thanks very much for both your suggestions.
When you refer to doing a 'double for loop', do you mean finding the average
for rowgrp and colgrp within each 6x6 block? If so, how would this be done so
that the whole data frame is covered? It would seem to me that the 'mean'
operation would need
Dear all,
I have a data frame of 2160 rows and 4320 columns, which I hope to condense to
a smaller dataset by finding averages of 6 by 6 blocks of values (to produce a
data frame of 360 rows by 720 columns).
How would I go about finding the mean of a 6 x 6 block, then find the mean of
the nex
3 matches
Mail list logo