I have a set:
lynx <- c(1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,4,4,4,5,5,6,7,8,9)
I want to return a set of all combinations with repetitions allowed from the above set, for example:
1 1 1 1 1
1 2 2 8 9
I used the combination function from library gtools but it doesn't help
I tried:
combination(n = 9, r = 5, v = lynx, repeats.allowed=TRUE)
which returned
[,1] [,2] [,3] [,4] [,5]
[1,] 1 1 1 1 1
[2,] 1 1 1 1 2
[3,] 1 1 1 1 3
[4,] 1 1 1 1 4
But the issue is that it also returns,
[152,] 1 1 2 8 8
which I don't want since there are no two 8s in the set.