I am trying to create a list of 4 datasets of different dimensions and store these results in data_m in order to have for example a dataset of dimension 50x20, one of 100x20, and so on... But every time that I run the code the I get that the data are rewritten and I get 4 datasets all equal and of dimensions equal to the last dimensions of the two for loops...
Hope that somebody can help me Thanks in advance
This is the code:
multinom <- list()
multinom_z <- list()
var_m <- list()
var_mzeros <- list()
data_m <- list()
data_mzeros <- list()
for (i in 1:4){
for (p in c(20, 50)){
for (n in c(50, 100)){
set.seed(123)
prob <- rep(1/p, p)
multinom[[i]] <- t(rmultinom(n, p, prob = prob))
zeros <- matrix(0, n, 85*p/100)
multinom_z[[i]] <- cbind(multinom[[i]], zeros)
data_m[[i]] <- data.frame(multinom[[i]])
}
}
}
question from:https://stackoverflow.com/questions/66052581/store-results-within-a-for-loop-in-r