[R] permutation
Pauline Gu
gu4 at llnl.gov
Tue Nov 26 18:02:54 CET 2002
Greg, Thank you so much for your help.
Pauline
At 09:54 PM 11/25/2002 -0500, Warnes, Gregory R wrote:
>The gregmisc package contains a function 'perumutations' which generates all
>permutations of n choose r. It also contains 'combinations' which generates
>all combinations, and which appears to match your example:
>
>
> > library(gregmisc)
>Loading required package: MASS
>
>Attaching package `gregmisc':
>
>
> The following object(s) are masked from package:base :
>
> lowess
>
> > permutations(n=4,r=4)
> [,1] [,2] [,3]
> [1,] 1 2 3
> [2,] 1 2 4
> [3,] 1 3 2
> [4,] 1 3 4
> [5,] 1 4 2
> [6,] 1 4 3
> [7,] 2 1 3
> [8,] 2 1 4
> [9,] 2 3 1
>[10,] 2 3 4
>[11,] 2 4 1
>[12,] 2 4 3
>[13,] 3 1 2
>[14,] 3 1 4
>[15,] 3 2 1
>[16,] 3 2 4
>[17,] 3 4 1
>[18,] 3 4 2
>[19,] 4 1 2
>[20,] 4 1 3
>[21,] 4 2 1
>[22,] 4 2 3
>[23,] 4 3 1
>[24,] 4 3 2
> > combinations(n=4,r=3)
> [,1] [,2] [,3]
>[1,] 1 2 3
>[2,] 1 2 4
>[3,] 1 3 4
>[4,] 2 3 4
>
>See the help pages for details.
>
>-Greg
>
> > -----Original Message-----
> > From: Pauline Gu [mailto:gu4 at llnl.gov]
> > Sent: Monday, November 25, 2002 7:55 PM
> > To: r-help at stat.math.ethz.ch
> > Subject: [R] permutation
> >
> >
> > Dear R experts,
> >
> > Is there any function in R that I can calculate the
> > permutation lists? I
> > would like to know if there is any generic one for finding all the
> > permutation of n choose k?
> >
> > For example:
> >
> > perms <- list(1:2)
> > perms <- add.ttt(3:4, perms)
> > should give me
> > > perms
> > [[1]]
> > [1] 3 4 1 2
> >
> > [[2]]
> > [1] 3 1 4 2
> >
> > [[3]]
> > [1] 3 1 2 4
> >
> > and perms <- add.ttt(5:6, perms)
> > should give me:
> > [[1]]
> > [1] 5 6 3 4 1 2
> >
> > [[2]]
> > [1] 5 3 6 4 1 2
> >
> > [[3]]
> > [1] 5 3 4 6 1 2
> >
> > [[4]]
> > [1] 5 3 4 1 6 2
> >
> > [[5]]
> > [1] 5 3 4 1 2 6
> >
> > [[6]]
> > [1] 5 6 3 1 4 2
> >
> > [[7]]
> > [1] 5 3 6 1 4 2
> >
> > [[8]]
> > [1] 5 3 1 6 4 2
> >
> > [[9]]
> > [1] 5 3 1 4 6 2
> >
> > [[10]]
> > [1] 5 3 1 4 2 6
> >
> > [[11]]
> > [1] 5 6 3 1 2 4
> >
> > [[12]]
> > [1] 5 3 6 1 2 4
> >
> > [[13]]
> > [1] 5 3 1 6 2 4
> >
> > [[14]]
> > [1] 5 3 1 2 6 4
> >
> > [[15]]
> > [1] 5 3 1 2 4 6
> >
> >
> > This example is just for those with k=2. How would I
> > calculate those for
> > any k?
> >
> > Thanks in advance for your help.
> >
> > Pauline
> >
> > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
> > -.-.-.-.-.-.-.-.-
> > r-help mailing list -- Read
> > http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> > Send "info", "help", or "[un]subscribe"
> > (in the "body", not the subject !) To:
> > r-help-request at stat.math.ethz.ch
> > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
> > _._._._._._._._._
> >
>
>
>LEGAL NOTICE
>Unless expressly stated otherwise, this message is confidential and may be
>privileged. It is intended for the addressee(s) only. Access to this
>E-mail by anyone else is unauthorized. If you are not an addressee, any
>disclosure or copying of the contents of this E-mail or any action taken
>(or not taken) in reliance on it is unauthorized and may be unlawful. If
>you are not an addressee, please inform the sender immediately.
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list