[R] AW: Permutations

Trenkler, Dietrich dtrenkler at nts6.oec.uni-osnabrueck.de
Sun Dec 17 12:08:00 CET 2000


		Niels Waller wrote: 

> Does anyone know of an R (or S-PLUS) function for delineating all possible
> combinations and permutations?

The following function delivers all permutations of 1:n.

all.perm <- function(n) {
    p <- matrix(1, ncol = 1)
    for (i in 2:n) {
        p <- pp <- cbind(p, i)
        v <- c(1:i, 1:(i - 1))
        for (j in 2:i) {
            v <- v[-1]
            p <- rbind(p, pp[, v[1:i]])
        }
    }
    p
}



Regards,

  *** D.Trenkler ***

====================================================================
Dietrich Trenkler               (trenkler at nts6.oec.uni-osnabrueck.de)
Statistik / Empirische Wirtschaftsforschung
Universitaet Osnabrueck
Rolandstrasse 8                           Phone: +49(0) 541-969-2753
D-49069 Osnabrueck                        Fax  : +49(0) 541-969-2745
GERMANY
====================================================================

>  
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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