Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将R中的矩阵转换为累积矩阵_R_Matrix - Fatal编程技术网

将R中的矩阵转换为累积矩阵

将R中的矩阵转换为累积矩阵,r,matrix,R,Matrix,在R中,我有一个矩阵,比如: 1 0 1 2 0 0 3 2 0 2 0 2 2 1 0 1 2 1 3 2 3 4 0 1 2 1 1 0 我想将此矩阵转换为累积版本,以便得到矩阵: 1 1 2 4 4 4 7 2 2 4 4 6 8 9 0 1 3 4 7 9 12 4 4 5 7 8 9 9 因此,矩阵2中的[i,j]th条目是矩阵1中所有元素的总和,因此i\u 1可以: > t(apply(mat, 1, cumsum)) 或 其中mat是原始矩阵。您可以执行以下操作: &g

在R中,我有一个矩阵,比如:

1 0 1 2 0 0 3
2 0 2 0 2 2 1
0 1 2 1 3 2 3
4 0 1 2 1 1 0
我想将此矩阵转换为累积版本,以便得到矩阵:

1 1 2 4 4 4 7
2 2 4 4 6 8 9
0 1 3 4 7 9 12
4 4 5 7 8 9 9
因此,矩阵2中的
[i,j]
th条目是矩阵1中所有元素的总和,因此
i\u 1可以:

> t(apply(mat, 1, cumsum))

其中
mat
是原始矩阵。

您可以执行以下操作:

> t(apply(mat, 1, cumsum))

其中
mat
是原始矩阵