So I know that the following command would store all possible combinations of a desired length y in a list, where y < j
:
lapply(y, function(x) combn(j,x))
But I don't want them all to be stored in a list because later on I will be accessing them only once so it's not efficient to store them in memory. Is there a way where I can just produce each combination in some sort of a loop or something, and then after I'm done performing a calculation, it would just give me the next combination? So basically I want to produce the combinations iteratively instead of storing them first.
So in pseudo code, what i'd like to have is:
#loop that will generate each possible combination one by one
loop{
operation that uses combination
}