0
我正在使用双循环来填充矩阵使用以下代码。使用双循环填充矩阵R
mat<-matrix(NA, nrow=2, ncol=2)
for (i in 1:2){
for (j in 3:4){
mat[i,j]<-c(i,j)
}
}
mat
我得到的错误是:
Error in '[<-'('*tmp*', i, j, value = c(3L, 1L)) :
subscript out of bounds
我在做什么错?
谢谢你的回答。这解释了很多。我试图用expand.grid(1:2,3:4)来完成,但不恰当的做法。 – Alph 2014-09-05 16:22:43