[R] All permutations
kjetil halvorsen
kjetilh at umsanet.edu.bo
Wed Sep 25 18:55:31 CEST 2002
As frequently in R, when something can be done it can be done in more
ways. There is also the combinat package on CRAN. Here is a comparision:
> system.time(permn(1:5))
[1] NA NA 0.16 NA NA
> system.time(permutations(5,5))
[1] NA NA 0.17 NA NA
> system.time(permn(1:8))
[1] NA NA 52.68 NA NA
> system.time(permutations(8,8))
[1] NA NA 71.5 NA NA
so the permn function from combinat seemxs to be marginally faster.
This is a slow windows 98 machine.
Kjetil Halvorsen
Juan Ramon Gonzalez wrote:
>
> Ravi,
>
> Look at the gregmisc package and "permutations" function
>
> Juan
>
> ----- Original Message -----
> From: "David Meyer" <david.meyer at ci.tuwien.ac.at>
> To: "Ravi Varadhan" <rvaradha at jhsph.edu>
> Cc: "R-Help (E-mail)" <r-help at stat.math.ethz.ch>
> Sent: Wednesday, September 18, 2002 7:24 PM
> Subject: Re: [R] All permutations
>
> > v <- 1:2
> > expand.grid(v,v,v)
> >
> > g.,
> > -d
> >
> > Ravi Varadhan wrote:
> > >
> > > Hi:
> > >
> > > I would like to obtain all permutations of size n containing the k
> distinct
> > > objects. For example, for size n=3 and k=2 objects (1 and 2), I want the
> > > following 8x3 matrix:
> > >
> > > 1 1 1
> > > 1 1 2
> > > 1 2 1
> > > 2 1 1
> > > 1 2 2
> > > 2 2 1
> > > 2 1 2
> > > 2 2 2
> > >
> > > Is there any R function to accomplish this?
> > >
> > > Thanks for the help,
> > > Ravi.
> > >
> >
> > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
> -.-.-
> > > 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
> > >
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
> _._
> >
> > --
> > Mag. David Meyer Wiedner Hauptstrasse 8-10
> > Vienna University of Technology A-1040 Vienna/AUSTRIA
> > Department of Tel.: (+431) 58801/10772
> > Statistics and Probability Theory mail: david.meyer at ci.tuwien.ac.at
> > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
> -.-.-
> > 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
> >
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
> _._
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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