mat 和asmatrix的区别_r中的matrix()和as.matrix()有什么区别?

矩阵获取数据和进一步的参数nrow和ncol.

?matrix

If one of ‘nrow’ or ‘ncol’ is not given, an attempt is made to

infer it from the length of ‘data’ and the other parameter. If

neither is given, a one-column matrix is returned.

as.matrix是一种针对不同类型具有不同行为的方法,但主要是从n * m输入返回n * m矩阵.

?as.matrix

‘as.matrix’ is a generic function. The method for data frames

will return a character matrix if there is only atomic columns and

any non-(numeric/logical/complex) column, applying ‘as.vector’ to

factors and ‘format’ to other non-character columns. Otherwise,

the usual coercion hierarchy (logical < integer < double <

complex) will be used, e.g., all-logical data frames will be

coerced to a logical matrix, mixed logical-integer will give a

integer matrix, etc.

它们之间的区别主要来自输入的形状,矩阵不关心形状,as.matrix做并将维护它(虽然细节取决于输入的实际方法,在您的情况下是无量纲向量对应于单个列矩阵.)输入是原始的,逻辑的,整数的,数字的,字符的还是复杂的等等并不重要.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值