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?
CodePudding user response:
You can use combinat::permn
:
x <- c(1, 1, 1, 1, 1, 2, 2, 2, 3, 3)
combinat::permn(x)