打印没有行和列索引的矩阵
问题描述:
如果我打印一个矩阵,它将在控制台中与行和列索引一起显示.例如
If I print a matrix, it is shown with row and column indices in the console. E.g.
> print(diag(3))
[,1] [,2] [,3]
[1,] 1 0 0
[2,] 0 1 0
[3,] 0 0 1
如何抑制列和行索引? IE.像这样的东西:
How can I suppress the column and row indices? I.e. something like this:
> print(diag(3), indices=FALSE)
1 0 0
0 1 0
0 0 1
我可以看到cwhmisc
程序包应包含printM
函数来执行此操作
I can see that the cwhmisc
package should contain a printM
function to do this according to the documentation but it is not there when I load cwhmisc. Also, this seems like something you should be able to to in base R.
答
函数 base
软件包中的prmatrix
可以解决此问题,它可以使用参数collab
和rowlab
:
prmatrix(diag(3), rowlab=rep("",3), collab=rep("",3))
1 0 0
0 1 0
0 0 1