在R中将矢量写入3D数组的第三维

时间:2017-01-10 21:15:47

标签: r multidimensional-array

我正在研究多波段光栅图像。对于处理,将Raster转换为矩阵,然后进行像素处理。我在将像素值写入空白3d数组时遇到问题,如下所述。

让我们假设

我有一个空白3D array

x = array(0,c(4,5,3))
x
, , 1

     [,1] [,2] [,3] [,4] [,5]
[1,]    0    0    0    0    0
[2,]    0    0    0    0    0
[3,]    0    0    0    0    0
[4,]    0    0    0    0    0

, , 2

     [,1] [,2] [,3] [,4] [,5]
[1,]    0    0    0    0    0
[2,]    0    0    0    0    0
[3,]    0    0    0    0    0
[4,]    0    0    0    0    0

, , 3

     [,1] [,2] [,3] [,4] [,5]
[1,]    0    0    0    0    0
[2,]    0    0    0    0    0
[3,]    0    0    0    0    0
[4,]    0    0    0    0    0

vector

y = c(5,14)

我想在y中复制3rd dimension of x的值,以便输出看起来如下所示

x
, , 1

     [,1] [,2] [,3] [,4] [,5]
[1,]    5    0    0    0    0
[2,]    0    0    0    0    0
[3,]    0    0    0    0    0
[4,]    0    0    0    0    0

, , 2

     [,1] [,2] [,3] [,4] [,5]
[1,]    14    0    0    0    0
[2,]    0    0    0    0    0
[3,]    0    0    0    0    0
[4,]    0    0    0    0    0

, , 3

     [,1] [,2] [,3] [,4] [,5]
[1,]    NA    0    0    0    0
[2,]    0    0    0    0    0
[3,]    0    0    0    0    0
[4,]    0    0    0    0    0

我在互联网上搜索过,但我找不到任何解决方案。

0 个答案:

没有答案