I have some data that I am trying to filter in dplyr, but I can't seem to get the code right to get it done. Here are the two data sets:
df1 <- data.frame(Chromosome = c("chr1", "chr1", "chr2", "chr3", "chr4"),
                  Position = c(5 ,12, 20, 25, 50), stringsAsFactors = FALSE)
> df1
  Chromosome Position
1       chr1        5
2       chr1       12
3       chr2       20
4       chr3       25
5       chr4       50
df2 <- data.frame(Chromosome = c("chr1", "chr3"), From = c(1, 20),
                  To = c(10, 80),stringsAsFactors = FALSE)
> df2
  Chromosome From To
1       chr1    1 10
2       chr3   20 80
What I would like to do is select those rows from the first table where the chromosome numbers are identical between the tables and the position is contained between the "From" and the "To" in the second table. So the output here would be:
  Chromosome Position
1       chr1        5
2       chr3       25
Any suggestions on how to write this in R? In particular I'd love to use dplyr functions, but not required.
 
     
     
    