1

First off, I'm pretty new to R, and this board, so please bear with me.

I have 2 data frames, and I want to use one to search the second. Specifically, I want a list of var from x where x$pos==y$chr and x$loc is within the range of start and end in y for each row.

Ideal output would be something like

rs1234  chr11 872365 bingo 872000   873000
rs2314  chr12  881000  boom  880000   881100

Any suggests are much appreciated!

> x
     var   pos    loc
1 rs1234 chr11 872365
2 rs2341 chr12 881000
3 rs3412 chr11 872010
4 rs4123  chr1 186543
> y
    chr  start    end  name
1 chr11 872000 873000 bingo
2 chr11 873100 874000 batta
3  chr12 880000 881100  boom
Psidom
  • 209,562
  • 33
  • 339
  • 356
Lea Jessop
  • 11
  • 1
  • I think you should check for `foverlaps` from `data.table` or `GRanges` packages – akrun Aug 12 '16 at 13:22
  • Thanks! I took at look at data.table and foverlaps looks like it would work great if I had start and end coordinates in x. What I'm trying to do is determine if the value in x$loc is included in the range created by y$start to y$end. Slightly different. I could just create start and end coordinates for x by subtracting and adding 1 to the values in loc and then calling foverlaps, but I'm guessing there is a smarter way of doing it. – Lea Jessop Aug 12 '16 at 21:23
  • Okay, i reopened it. – akrun Aug 13 '16 at 02:01

0 Answers0