If I have:
mylist <- lapply(1:10, function(x) matrix(NA, nrow=2, ncol=2))
And I want to replace, for example, the first, second and fifth elements in the list with:
mymatrix=cbind(c(1,1),c(1,1))
What can I do? I tried:
mylist[c(1,2,5)]=mymatrix
But I can not replace the new matrix, because it is a different list, and with the help [[]]I can access only one element.
I think I need to use the function lapply, but I cannot figure out which direction.
source
share