Since l
does not already have a a vector, you don't want to specify a position in the first element of the list. Try:
l <- list()
l[[1]] <- 1
For adding additional values to specific places in this new vector, it is best to set the vector up with the known length of values to be filed in (for speed reasons; see why here). Here is an example loop:
n <- 100
l <- list()
l[[1]] <- NaN*seq(n)
for(i in seq(n)){
l[[1]][i] <- i
}
Regarding your specific example:
k <- 7
ind <- 7
mcorrelation <- vector(mode="list", k)
for(i in seq(k)){
mcorrelation[[i]] <- NaN*seq(ind)
for (j in seq(ind)){
mcorrelation[[i]][j] <- rnorm(1)
}
}
mcorrelation