# Ordered Permutation

#### Zaheer Abbas

##### New Member
Is there any way in R to generate ordered permutation and used them one by one.

#### Dason

The combinat package can do this for you fairly easily
Code:
library(combinat)
permn(1:3)
# you can use whatever you want though...
permn(c("a", "b", "c"))

#### Zaheer Abbas

##### New Member
@Dason. thanks a lot, but this does not work for large size i.e. permn(1:36), further, can i store these permutation into a matrix and use one by one through for loop in a check process?

#### bryangoodrich

##### Probably A Mammal
Since it returns a list of equal length vectors, you can use do.call to row bind them all together

Code:
do.call("rbind", permn(1:3))
What do.call does is execute "rbind" with the elements of permn(1:3), in this case, as the arguments. In other words, if permn(1:3) were stored in 'x', then it's equivalent to running

Code:
rbind(x[[1]], x[[2]], x[[3]], x[[4]], x[[5]], x[[6]])
Not very nice to do, especially if you had to bind 36 elements! So when you get list objects you need to reshape into something a bit nicer, always think do.call. It can often prove useful.

#### Zaheer Abbas

##### New Member
@bryangoodrich, thanks dear. do call really works here to generate a matrix but the matter of large permutation is still unsolved. I further want to generate (nPr) permutations, i.e 37P10 etc.