我在工作区中有两个元素rr
和ll
(两个矩阵)
我做
Warning message: In cbind(ll, rr) : number of rows of result is not a multiple of vector length (arg 2) dim(ll) # [1] 3008 11 length(rr) #[1] 3008
怎么可能?
为了说明Marta的评论:
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
为了说明Heroka的评论:
dim(ll) # [1] 6 5 dim(rr) # [1] 1 6
If ll
是矩阵和rr
向量(R sense),即
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))