Quantcast
Viewing latest article 2
Browse Latest Browse All 6

Answer by Alexander Heath for Creating multiple matrices with a for loop

You're missing the initialization of valuematrix. You can do this through

valuematrix <- list()

just before the for loop.

You might also consider using lapply to solve this problem. It automatically stores the matrices in a list.

y <- matrix(1:300, 100, 3)rep = 200matList <- lapply(1:ncol(y), function(i) replicate(rep, y[,i])) 

Viewing latest article 2
Browse Latest Browse All 6

Trending Articles