Re: [R] Lexical Permutation Algorithm in R

2008-12-05 Thread Robin Hankin
Rory there are several packages that perform this. I would use permn() of the combinat library, then, if lexicographical order is important, sort it explicitly. HTH rksh [EMAIL PROTECTED] wrote: Hi all Here is a rather naive implementation of the SEPA algorithm for generating lexical p

[R] Lexical Permutation Algorithm in R

2008-12-05 Thread Rory.WINSTON
Hi all Here is a rather naive implementation of the SEPA algorithm for generating lexical permutations: lexperm3 <- function(x, n=length(x)) { perms <- list() k <- 1 perms[[k]] <- x k <- k + 1 for (y in 1:(factorial(n)-1)) { i <- n-1 while (x[i] > x[i+1] && i > 0) { i <- i - 1 }