矩阵获取数据和进一步的参数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做并将维护它(虽然细节取决于输入的实际方法,在您的情况下是无量纲向量对应于单个列矩阵.)输入是原始的,逻辑的,整数的,数字的,字符的还是复杂的等等并不重要.