I have a function that creates a matrix and I want to call this function a thousand times such that in the end I have a list of 1000 matrices. Here is an example:
set.seed(1)
gen_mat <- function(x) matrix(c(1, 1, 1, x + rnorm(1)), nrow = 2)
Now, I tried replicate(10, gen_mat(1))
, but this returns an array and not a list. How to do it?
?replicate
:replicate(10, gen_mat(1), simplify=FALSE)
– Bayly