I have this R function to generate a matrix of all combinations of k numbers between 0 and n whose sum equals n. This is one of the bottlenecks of my program as it becomes extre
The following can be done with lapply.
ls1 <- list() for(i in 1:k) { ls1[[i]] <- 0:n }
Try substituting this is and see if you get any speed up.
ls1 = lapply(1:k,function(x) 0:n)
I changed 'ls' to 'ls1' because ls() is an R function.