Hi i would like to create 15 Matrices with different columns,i tried this code
for(i in 1:15){Di=matrix(0,i,1000)}
for(i in 1:15){for(k in 1:i){for(j in 1:1000){Di[k,j]=runif(1,-1,1)}}}
but Di
did not create D1,D2 vs. matrices for me Di
stayed as one whole matrix, how can I create 15 different matrices?
You should use a list
for this:
l <- vector(mode="list", length=15)
for (i in seq(along=l)) {
l[[i]] <- matrix(runif(i*1000, -1, 1), nrow=1000, ncol=i)
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.