I have two data frames and wish to use the value in one (DF1$pos
) to search through two columns in DF2 (DF2start, DF2end) and if it falls within those numbers,
You could also use IRanges
source("http://bioconductor.org/biocLite.R")
biocLite("IRanges")
library(IRanges)
DF1N <- with(DF1, IRanges(pos, pos))
DF2N <- with(DF2, IRanges(start, end))
DF1$name <- DF2$annot[subjectHits(findOverlaps(DF1N, DF2N))]
DF1
# ID pos name
#1 chr 12 a1
#2 chr 542 a3
#3 chr 674 a3