打印没有行和列索引的矩阵 [英] Print a matrix without row and column indices

查看:59
本文介绍了打印没有行和列索引的矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我打印一个矩阵,它将在控制台中与行和列索引一起显示.例如

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 可以解决此问题,它可以使用参数collabrowlab:

prmatrix(diag(3), rowlab=rep("",3), collab=rep("",3))

 1 0 0
 0 1 0
 0 0 1

这篇关于打印没有行和列索引的矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆