尝试光栅包中的aggregate
功能。这是一个简单的例子:
R> library(raster)
R> x <- matrix(1:81, 9, 9)
R> x
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
[1,] 1 10 19 28 37 46 55 64 73
[2,] 2 11 20 29 38 47 56 65 74
[3,] 3 12 21 30 39 48 57 66 75
[4,] 4 13 22 31 40 49 58 67 76
[5,] 5 14 23 32 41 50 59 68 77
[6,] 6 15 24 33 42 51 60 69 78
[7,] 7 16 25 34 43 52 61 70 79
[8,] 8 17 26 35 44 53 62 71 80
[9,] 9 18 27 36 45 54 63 72 81
R> r <- raster(x)
R> r
class : RasterLayer
dimensions : 9, 9, 81 (nrow, ncol, ncell)
resolution : 0.1111, 0.1111 (x, y)
extent : 0, 1, 0, 1 (xmin, xmax, ymin, ymax)
coord. ref. : NA
data source : in memory
names : layer
values : 1, 81 (min, max)
R> res <- aggregate(r, fact=3, fun=mean)
R> res
class : RasterLayer
dimensions : 3, 3, 9 (nrow, ncol, ncell)
resolution : 0.3333, 0.3333 (x, y)
extent : 0, 1, 0, 1 (xmin, xmax, ymin, ymax)
coord. ref. : NA
data source : in memory
names : layer
values : 11, 71 (min, max)
R> as.matrix(res)
[,1] [,2] [,3]
[1,] 11 38 65
[2,] 14 41 68
[3,] 17 44 71
fact
如果是具有两个整数值的向量,则可以指定不同的水平和垂直聚合因子。