R中的矩阵警告

时间:2016-01-05 07:53:37

标签: r matrix warnings

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

我做

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

怎么可能?

1 个答案:

答案 0 :(得分:6)

说明Marta的评论:

<h3> CSS range validation </h3>
Enter your age
<input class="validate" type="number" min="1" max="100">

<h3> NO CSS range validation </h3>
Enter your age
<input type="number" min="1" max="100">

说明Heroka的评论:

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是向量(R sense),即

rr

要删除列名:

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