rpois函数对矩阵

时间:2017-09-22 07:59:24

标签: r matrix

我有一个数字矩阵,我想将rpois应用于矩阵的每个元素。 矩阵看起来像这样

[1,]               112                119                 222                85                  101                  99

[2,]               117                154                 205               123                 113                 133

[3,]             28708              19994               33608             21151               11579               15436

[4,]                 0                  6                  16                 0                   0                   7

如何将rpois函数应用于矩阵的每个元素?

1 个答案:

答案 0 :(得分:5)

假设您希望矩阵元素为lambda参数:

outputMatrix <- rpois(length(inputMatrix), inputMatrix)
dim(outputMatrix) <- dim(inputMatrix)

不要使用apply,因为这实际上只是对每个元素的循环。