0

I am working/struggling on some R code where I would like to list all possible combinations of elements within a vector. For example my starting vector being: {1,1,1,1,1,2,2,2,3,3}

I would like the output for example to be:

[1] {1,1,1,1,1,2,2,2,3,3}
[2] {1,1,1,1,1,2,2,3,2,3}
[3] {1,1,1,1,1,2,3,2,2,3}
[4] {1,1,1,1,1,3,2,2,2,3}
[5] {1,1,1,1,3,2,2,2,2,3}
...
[n] {3,3,2,2,2,1,1,1,1,1}

Any thoughts?

  • Does this answer your question? [Generating all distinct permutations of a list in R](https://stackoverflow.com/questions/11095992/generating-all-distinct-permutations-of-a-list-in-r) – divibisan Oct 14 '22 at 21:24

1 Answers1

0

You can use combinat::permn:

x <- c(1, 1, 1, 1, 1, 2, 2, 2, 3, 3)
combinat::permn(x)
Maël
  • 45,206
  • 3
  • 29
  • 67