I have a matrix that i want to duplicate n times in a list. Obviously the rep() function does not work on matrices, so does anyone have a good suggestion how to make this be
You can use either lapply()
n <- 3
x <- lapply(seq_len(n), function(X) jwprox)
str(x)
# List of 3
# $ : logi [1:15, 1:15] NA NA NA NA NA NA ...
# $ : logi [1:15, 1:15] NA NA NA NA NA NA ...
# $ : logi [1:15, 1:15] NA NA NA NA NA NA ...
or replicate()
:
xx <- replicate(n, jwprox, simplify=FALSE)
identical(x,xx)
# [1] TRUE
(FWIW, replicate()
is just a sometimes-handy wrapper for sapply()
and, in turn, lapply()
.)