tresbot - 7 months ago 29

R Question

I'm trying to create a list of permutations of a list, such that, for example,

`perms(list("a", "b", "c"))`

`list(list("a", "b", "c"), list("a", "c", "b"), list("b", "a", "c"),`

list("b", "c", "a"), list("c", "a", "b"), list("c", "b", "a"))

I'm not sure how to proceed, any help would be greatly appreciated.

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

`combinat::permn`

will do that work:

```
> library(combinat)
> permn(letters[1:3])
[[1]]
[1] "a" "b" "c"
[[2]]
[1] "a" "c" "b"
[[3]]
[1] "c" "a" "b"
[[4]]
[1] "c" "b" "a"
[[5]]
[1] "b" "c" "a"
[[6]]
[1] "b" "a" "c"
```

Note that calculation is huge if the element is large.

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**