# [R] A "matching problem"

MacQueen, Don macqueen1 at llnl.gov
Mon Jul 30 20:13:08 CEST 2012

```Does this do what you want?
(using just three letters to keep the list of results short)

> tmp <- expand.grid(v=letters[1:3],V=LETTERS[1:3])
> tmp
v V
1 a A
2 b A
3 c A
4 a B
5 b B
6 c B
7 a C
8 b C
9 c C
>
> subset(tmp, tolower(tmp\$V) != tmp\$v)
v V
2 b A
3 c A
4 a B
6 c B
7 a C
8 b C

-Don

--
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062

On 7/30/12 7:55 AM, "Christofer Bogaso" <bogaso.christofer at gmail.com>
wrote:

>Dear all, I was encountering with a typical Matching problem and was
>wondering whether R can help me to solve it directly.
>
>Let say, I have 2 vectors of equal length:
>vector1 <- LETTERS[1:6]
>vector2 <- letters[1:6]
>
>Now I need to match these 2 vectors with all possible ways like:
>
>(A,B,C,D,E) & (a,b,c,d,e) is 1 match. Another match can be (A,B,C,D,E) &
>(b,a,c,d,e), however there cant be any duplication.
>
>Is there any direct way to doing that in R?
>
>Thanks and regards,
>
>______________________________________________
>R-help at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help