R中的矩阵警告

R中的矩阵警告,r,matrix,warnings,R,Matrix,Warnings,我在工作区中有两个元素rr和ll(两个矩阵) 我知道 这怎么可能呢?为了说明玛尔塔的评论: set.seed(42) ll <- matrix(rnorm(30),6, 5) rr <- matrix(rnorm(6), 1, 6) dim(ll) # [1] 6 5 length(rr) # [1] 6 cbind(ll, rr) Error in cbind(ll, rr) : number of rows of matrices must match (see arg 2

我在工作区中有两个元素
rr
ll
(两个矩阵)

我知道


这怎么可能呢?

为了说明玛尔塔的评论:

set.seed(42)
ll <- matrix(rnorm(30),6, 5)
rr <- matrix(rnorm(6), 1, 6)
dim(ll)
# [1] 6 5
length(rr)
# [1] 6
cbind(ll, rr)
Error in cbind(ll, rr) : 
  number of rows of matrices must match (see arg 2)

cbind(ll, t(rr))
#            [,1]        [,2]       [,3]       [,4]       [,5]       [,6]
# [1,]  1.3709584  1.51152200 -1.3888607 -2.4404669  1.8951935  0.4554501
# [2,] -0.5646982 -0.09465904 -0.2787888  1.3201133 -0.4304691  0.7048373
# [3,]  0.3631284  2.01842371 -0.1333213 -0.3066386 -0.2572694  1.0351035
# [4,]  0.6328626 -0.06271410  0.6359504 -1.7813084 -1.7631631 -0.6089264
# [5,]  0.4042683  1.30486965 -0.2842529 -0.1719174  0.4600974  0.5049551
# [6,] -0.1061245  2.28664539 -2.6564554  1.2146747 -0.6399949  0.4554501
dim(ll)
# [1] 6 5
dim(rr)
# [1] 1 6
如果
ll
是矩阵,而
rr
是向量(R感),即


什么是
dim(rr)
?你能让你的例子重现吗?也许你的
rr
是一个向量(不是矩阵),所以它是水平方向的。尝试转置它。@Marta将使用向量(R中没有方向)。不适用于1x3008矩阵。同时提供
dim(rr)
@jogo我敢打赌我的家庭农场是
NULL
:)(呃,帕斯卡在回答中已经提到了)
dim(ll)
# [1] 6 5
dim(rr)
# [1] 1 6
rr <- as.numeric(rr)
dim(rr)
# NULL
length(rr)
# 6
cbind(ll, rr)
#                                                                      rr
# [1,]  1.3709584  1.51152200 -1.3888607 -2.4404669  1.8951935  0.4554501
# [2,] -0.5646982 -0.09465904 -0.2787888  1.3201133 -0.4304691  0.7048373
# [3,]  0.3631284  2.01842371 -0.1333213 -0.3066386 -0.2572694  1.0351035
# [4,]  0.6328626 -0.06271410  0.6359504 -1.7813084 -1.7631631 -0.6089264
# [5,]  0.4042683  1.30486965 -0.2842529 -0.1719174  0.4600974  0.5049551
# [6,] -0.1061245  2.28664539 -2.6564554  1.2146747 -0.6399949  0.4554501
cbind(ll, unname(rr))