[R] A "matching problem"
arun
smartpink111 at yahoo.com
Mon Jul 30 20:08:59 CEST 2012
Hi,
Not sure what you wanted.
But, this will be just a subset of possible combinations as you described in the post.
vector1<-sample(LETTERS[1:6])
vector2<-sample(letters[1:6])
b<-list()
for(i in 1:length(vector1)){
b[[i]]<-list()
b[[i]]<-sample(vector1)
}
d<-list()
for(j in 1:length(vector2)){
d[[j]]<-list()
d[[j]]<-sample(vector2)
}
as.data.frame(cbind(do.call(rbind,b),do.call(rbind,d)))
V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12
1 E F D C A B c f b d e a
2 B C E A F D c f a d b e
3 D A E C B F b a f e d c
4 B F A D E C d c b f e a
5 D B C E F A a c f b d e
6 E C B A D F f e b d a c
A.K.
----- Original Message -----
From: Christofer Bogaso <bogaso.christofer at gmail.com>
To: r-help at r-project.org
Cc:
Sent: Monday, July 30, 2012 10:55 AM
Subject: [R] A "matching problem"
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
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list