Populate list with same object efficiently
list, memory-management, r
Solution
Make a list of 1 and replicate it.
L <- rep(list(x), 1000)
Problem
Suppose I have some object (any object), for example: ``` X <- array(NA,dim=c(2,2)) ``` Also I have some list: ``` L <- list() ``` I want `L[[1]]`, `L[[2]]`, `L[[3]]`,...,`L[[100]]`,...,`L[[1000]]` all to have the object `X` inside it. That is, if I type into the console `L[[i]]`, it will return `X`, where i is in {1,2,...,1000}. How do I do this efficiently without relying on a `for loop` or `lapply`?