假设我有这个矩阵:
View
然后我收到了这条警告信息:
Matrix <- c(5, 2, 3, 1, 4,
0, 2, 3, 4, 1,
0, 0, 3, 4, 1,
0, 0, 0, 4, 1,
0, 0, 0, 0, 1)
Matrix <- matrix(Matrix, 5, 5)
fam <- list()
for (i in 1:3){
fam[i] <- array(0, dim = dim(Matrix))
}
然后结果不被接受:
Warning messages:
1: In fam[i] <- array(0, dim = dim(Matrix)) :
number of items to replace is not a multiple of replacement length
2: In fam[i] <- array(0, dim = dim(Matrix)) :
number of items to replace is not a multiple of replacement length
3: In fam[i] <- array(0, dim = dim(Matrix)) :
number of items to replace is not a multiple of replacement length
但是,如果没有列表,它可以正常工作!!
> fam
[[1]]
[1] 0
[[2]]
[1] 0
[[3]]
[1] 0
哪里是我的错误?
答案 0 :(得分:1)
而不是fam[i]
尝试fam[[i]]
。
答案 1 :(得分:0)
[[ selects a single element of a list
for (i in 1:3){
fam[[i]] <- array(0, dim = dim(Matrix))
}