suppose n=3 then output should be: a vector containing vectors: 123 213 132 231 321
This will solve your question:
install.packages("combinat")
require(combinat)
permn(1:3)
Also the functions: choose, combn ,expand.grid Might prove useful for you in the future.
library(gtools)
permutations(3,3)
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 1 3 2
[3,] 2 1 3
[4,] 2 3 1
[5,] 3 1 2
[6,] 3 2 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With