I have the following dataframe:
sp <- combn(c(\"sp1\",\"sp2\",\"sp3\",\"sp4\"),2) d <- data.frame(t(sp),\"freq\"=sample(0:100,6))
and
Do not make x1 and x2 factors. Just use vectors. Use %in% for the logical test.
x1
x2
%in%
sp <- combn(c("sp1","sp2","sp3","sp4"),2) d <- data.frame(t(sp),"freq"=sample(0:100,6)) x1 <- c("sp1","sp2") x2 <- c("sp3","sp4") sub <- d[d$X1 %in% x1 & d$X2 %in% x2,]