Sorry, correction: The second index matrix is the matrix of elements not in the first, not another combination, this time 3 out of 10.
Change this in my first post > > inxmat <- with(DF, combn(ID, 3)) > meansDist2 <- apply(inxmat, 2, function(jnx) f(jnx, DF$value, 45)) > (i2 <- which(meansDist2 == min(meansDist2))) > to this inxmat2 <- with(DF, apply(inxmat, 2, function(x) setdiff(ID, x))) meansDist2 <- apply(inxmat2, 2, function(jnx) f(jnx, DF$value, 45)) (i2 <- which(meansDist2 == min(meansDist2))) Rui Barradas -- View this message in context: http://r.789695.n4.nabble.com/select-rows-by-criteria-tp4434812p4435408.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ 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.