Skip to content
Prev 301733 / 398506 Next

A "matching problem"

On Mon, Jul 30, 2012 at 08:40:59PM +0545, Christofer Bogaso wrote:
Hi.

If i understand correctly, all matches are obtained by taking all
permutations of (a,b,c,d,e) and relating them to unchanged (A,B,C,D,E).
Try the following.

  library(permute)
  vector2 <- letters[1:3]
  p <- allPerms(length(vector2), observed=TRUE)
  matrix(vector2[p], nrow=nrow(p), ncol=ncol(p))
  
       [,1] [,2] [,3]
  [1,] "a"  "b"  "c" 
  [2,] "a"  "c"  "b" 
  [3,] "b"  "a"  "c" 
  [4,] "b"  "c"  "a" 
  [5,] "c"  "a"  "b" 
  [6,] "c"  "b"  "a" 

The rows of the resulting matrix are all permutations of vector2.

Hope this helps.

Petr Savicky.