# Re: [R] combinatorics

From: Ted Harding <Ted.Harding_at_nessie.mcc.ac.uk>
Date: Fri 13 Oct 2006 - 16:40:24 GMT

On 13-Oct-06 Robin Hankin wrote:

```> Hi
>
> How do I generate all ways of ordering  sets of indistinguishable
> items?
>
> suppose I have two A's, two B's and a C.
>
> Then I want
>
> AABBC
> AABCB
> AACBC ---->> I think you mean AACBB here!
> ABABC
> . . .snip...
> BBAAC
> . . .snip...
> CBBAA
>
> [there are 5!/(2!*2!) = 30 arrangements.  Note AABBC != BBAAC]
>
> How do I do this?

```

Meanwhile, a problem of the order of the one you describe above can be solved quite slickly:

X<-c("A","A","B","B","C")
library(combinat)

##[result below stripped of " quotes for clarity] unique(array(permn(X)))
[]

```    A A B B C

[]
   A A B C B

[]
   A A C B B

[]
   A C A B B

[]
   C A A B B

[]
   A B A B C

[]
   A B A C B

[]
   A B C A B
```

[]
```    A C B A B
```

[]
```    C A B A B
```

[]
```    C B A A B
```

[]
```    B C A A B
```

[]
```    B A C A B
```

[]
```    B A A C B
```

[]
```    B A A B C
```

[]
```    B A B A C
```

[]
```    B A B C A
```

[]
```    B A C B A
```

[]
```    B C A B A
```

[]
```    C B A B A
```

[]
```    C A B B A
```

[]
```    A C B B A
```

[]
```    A B C B A
```

[]
```    A B B C A
```

[]
```    A B B A C
```

[]
```    B B A A C
```

[]
```    B B A C A
```

[]
```    B B C A A
```

[]
```    B C B A A
```

[]

 C B B A A

However, the above simple function will quickly get short of breath if the total number of items gets much above, say 10.

Hoping this helps!
Ted.

E-Mail: (Ted Harding) <Ted.Harding@nessie.mcc.ac.uk> Fax-to-email: +44 (0)870 094 0861
```Date: 13-Oct-06                                       Time: 17:40:20
------------------------------ XFMail ------------------------------

______________________________________________
```
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sat Oct 14 04:15:30 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 13 Oct 2006 - 19:30:09 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.