[R] selecting rows based on multiple criteria
Enrico R. Crema
enryu_crema at yahoo.it
Wed May 1 13:54:33 CEST 2013
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
More information about the R-help
mailing list