0

I have the numbers 1, 2, 3, 4.

I want to create all the vectors of length 14, such that the number 1 appears 4 times, 2 appears 3 times, 3 appears 5 times and 4 appears 2 times, that is:

4 times + 3 times + 5 times + 2 times = length 14.

For example, three of these vectors are:

1,1,1,1,2,2,2,3,3,3,3,3,4,4

1,1,1,2,1,2,2,3,3,3,3,3,4,4

1,1,2,1,1,2,2,3,3,3,3,3,4,4

and so on.

I have tried to use combn but it was not successful.

The number of these vector is equal to choose(14,4)*choose(14-4,3)*choose(14-4-3,5)*choose(14-4-3-5,2).

EDIT

Using permn(c(1,1,1,1,2,2,2,3,3,3,3,3,4,4)), I will create, for example the vector 1,1,1,1,2,2,2,3,3,3,3,3,4,4 many times, that is I will have duplicated vectors. Then I have to use unique. But it is not worth creating duplicated vectors and then to keep the unique ones, since I want only the unique ones, that is the vector 1,1,1,1,2,2,2,3,3,3,3,3,4,4 just one time.

So, the answer in question Generating all distinct permutations of a list in R creates duplicated vectors.

Vassilis Chasiotis
  • 427
  • 1
  • 3
  • 15

0 Answers0