Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.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 - Fatal编程技术网

R 构建矩阵

R 构建矩阵,r,R,我想构造一个维数为T x T的矩阵。在第一行和最后一列中,我想要所有的零。此外,从第二行到第T行,从第一列到第T-1列,我想要一个单位矩阵。在T=4的情况下,应如下所示: 1. column 2. column 3. column 4. column 1. row: 0 0 0 0 2. row: 1 0 0 0 3. row:

我想构造一个维数为T x T的矩阵。在第一行和最后一列中,我想要所有的零。此外,从第二行到第T行,从第一列到第T-1列,我想要一个单位矩阵。在T=4的情况下,应如下所示:

        1. column    2. column   3. column  4. column
1. row:     0           0           0           0

2. row:     1           0           0           0

3. row:     0           1           0           0

4. row:     0           0           1           0
我希望这是有道理的


谢谢。

看看
?diag
rbind
?cbind

n <- 4
rbind(rep(0, n), cbind(diag(1, n-1), rep(0, n-1)))

     [,1] [,2] [,3] [,4]
[1,]    0    0    0    0
[2,]    1    0    0    0
[3,]    0    1    0    0
[4,]    0    0    1    0
n也可以执行
rbind(0,diag(1,n-1,n))