[R] combinatorics

jim holtman jholtman at gmail.com
Fri Oct 13 18:02:37 CEST 2006


Use 'permutations' in 'gtools'

x <- permutations(5,5)
y <- c('a','a','b','b','c')[x]
dim(y) <- dim(x)
unique(y)



On 10/13/06, Robin Hankin <r.hankin at noc.soton.ac.uk> 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
> ABABC
> . . .snip...
> BBAAC
> . . .snip...
> CBBAA
>
> [there are 5!/(2!*2!) = 30 arrangements.  Note AABBC != BBAAC]
>
> How do I do this?
>
>
>
>
>
> --
> Robin Hankin
> Uncertainty Analyst
> National Oceanography Centre, Southampton
> European Way, Southampton SO14 3ZH, UK
>  tel  023-8059-7743
>
> ______________________________________________
> R-help at 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.
>


-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?



More information about the R-help mailing list