I have a problem where I have k items, say {0,1}
, and I have to enumerate all possible N
draws, say N=3
. That is, I am trying to find all possible samples of a given size from a vector, with replacement.
I can get there via the following loop approach:
for (i1 in c(0,1)){
for (i2 in c(0,1)){
for (i3 in c(0,1)){
print(paste(i1,i2i3,collapse="_"))
}}}
However, this feels like a kludge. Is there a better way to do this using base R?