blazej - 5 months ago 24

R Question

For starters, forgive my math terminology ignorance (I'll edit this question, once errors in my vocabulary are pointed out).

How can I print a complete set of 3 element permutation of a 10 element vector in R?

Let's assume a vector consists of 10 unique letters A to J

`x<- LETTERS[seq( from = 1, to = 10 )]`

I'd like to list (print) all possible

ABC, ACB, ABD, ADB ...

Thank you for any hints

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

Answer Source

This can be easily done using the gtools package.

```
prm <- gtools::permutations(n=10, r=3, v=LETTERS[1:10])
```

Then you can apply paste0 across the rows to get a vector.

```
apply(prm, 1, function(x)paste0(x, collapse=''))
```

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