Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zisis86
    Member
    • Mar 2013
    • 10

    #1

    Matching a column from a data frame on the columns of another data frame

    I got two big data frames, one (df1) has this structure

    V1 V2 V3
    1 Chr1 7507 10944
    2 Chr1 10944 13170
    3 Chr1 13170 20065
    4 Chr1 20065 28273
    5 Chr1 28273 29960
    6 Chr1 29960 36599
    7 Chr1 36599 37513
    8 Chr1 37513 40360
    9 Chr1 40360 48796
    10 Chr1 48796 50661

    The other (df2) has this

    V1 V2 V3 V4 V5
    1 Chr1 7507 7507 1 1
    2 Chr1 10944 10944 1 2
    3 Chr1 13170 13170 1 22
    4 Chr1 20065 20065 1 3
    5 Chr1 28273 28273 1 161
    6 Chr1 29960 29960 1 10
    7 Chr1 36599 36599 1 604
    8 Chr1 37513 37513 1 117
    9 Chr1 40360 40360 1 8
    10 Chr1 48796 48796 1 3
    what I'm trying to do is to check if the column V2 or V3 (is the same) of df2 is = or between the range of V2 and V3 of df1 then I want to write the value of V5 of df2 in a new column in df1 if not write 0. the result that i want would be like :

    Chr1 7507 10944 1
    Chr1 10944 13170 2
    Chr1 13170 20065 22
    Chr1 20065 28273 3
    Chr1 28273 29960 161
    Chr1 29960 36599 10
    Chr1 36599 37513 604
    Chr1 37513 40360 117
    Chr1 40360 48796 8
    .
    .
    .
    Do you know any good way to do this?
    Thank you very much.
    Last edited by zisis86; 05-28-2014, 05:38 AM.
  • dpryan
    Devon Ryan
    • Jul 2011
    • 3478

    #2
    The simplest solution is to make these GRanges objects and then use findOverlaps. You can then add meta information columns to the first dataset (just 2 columns of 0s) and then increment those values according to the overlap values. This has the benefit of taking care of cases where there are multiple overlaps.

    Comment

    • bioBob
      Member
      • Mar 2011
      • 72

      #3
      Do you want to compare these line by line? Also, are V2 and V3 always the same?

      If so, why not use an ifelse statement in R?

      df3<-cbind(df1,nrow(df1) ##just adds another column to the df equal to 0
      df3[,4]<-ifelse((df2[,2]>(df1[,2]-1) || df2[,2]<(df1[,3]+1)),df2[,5],df3[,4])

      not tested, but something like this should work if you are going line by line

      Comment

      Latest Articles

      Collapse

      • SEQadmin2
        Multiomic Liquid Biopsy: What DNA/RNA Panels Reveal That DNA Alone Can’t
        by SEQadmin2



        Tumors contain complex mixtures of cell populations that evolve in response to treatment and host-specific factors. Tissue biopsies provide only static snapshots of a tumor’s state. But what if we could follow that evolution over time using a minimally invasive technique?

        Liquid biopsies can detect tumor-derived material circulating in the bloodstream, providing a way to study treatment response, detect emerging resistance, and discover new biomarkers. Circulating
        ...
        10-14-2026, 09:55 AM
      • SEQadmin2
        New Genomics Technologies Take Aim at Long-Standing Limits
        by SEQadmin2


        Researchers using sequencing and genomics tools often have to make trade-offs. They can choose between speed or scale, short reads or long-range information, or targeted panels or a view of the whole transcriptome. New technologies that have been released this year are built to address those tough choices.

        We asked six companies the same four questions to learn about their latest products. The new technologies bring a lot to the table, including rethinking sequencing
        ...
        09-28-2026, 10:25 AM

      ad_right_rmr

      Collapse

      News

      Collapse

      Topics Statistics Last Post
      Started by SEQadmin2, 10-15-2026, 10:52 AM
      0 responses
      16 views
      0 reactions
      Last Post SEQadmin2  
      Started by SEQadmin2, 10-14-2026, 05:39 AM
      0 responses
      21 views
      0 reactions
      Last Post SEQadmin2  
      Started by SEQadmin2, 10-13-2026, 09:56 AM
      0 responses
      22 views
      0 reactions
      Last Post SEQadmin2  
      Started by SEQadmin2, 10-09-2026, 11:14 AM
      0 responses
      27 views
      0 reactions
      Last Post SEQadmin2  
      Working...