match(interaction(choice),interaction(coord)) #[1] 2 11 12 A.K.
----- Original Message ----- From: Enrico R. Crema <enryu_cr...@yahoo.it> To: r-help@r-project.org Cc: Sent: Wednesday, May 1, 2013 7:54 AM Subject: [R] selecting rows based on multiple criteria Dear List, I am struggling with the following problem. Suppose I have the following data.frame: coord<-expand.grid(x=1:10,y=1:10) and I want to extract the row numbers of those matching the criteria defined by the following data.frame: choice<-data.frame(x=c(2,1,2),y=c(1,2,2)) the result should return in this case: 2,11,12 All I managed to do is the following: which(data coord$x%in%choice$x & coord$y%in%choice$y); which returns c(1,2,11,12)... which includes also the first row... Any thoughts? Enrico ______________________________________________ R-help@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. ______________________________________________ R-help@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.