Here is another solution, using apply() and lapply().
# list of sequences corresponding to each row in data1: seqlist <- apply(data1, 1, function(x)seq(from=x[1], to=x[2])) # Find which rows of data2 are inside those sequences: rowsInSeq<- unlist(lapply(seqlist , function(x)which(data2$position %in% x))) # use that to index data1: data2[rowsInSeq,] greetings, remko -- View this message in context: http://r.789695.n4.nabble.com/complex-search-between-dataframes-tp3569104p3569698.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.