[R] complex search between dataframes

Remko Duursma remkoduursma at gmail.com
Fri Jun 3 02:07:57 CEST 2011


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.



More information about the R-help mailing list