0

How can i shift the boundaries of df1 (Start and End columns) to the closest Position columns in marker file. I want to adjust the Start and End column of df1 to the nearest match found in marker provided Chromosome column should match.

x <- "Sample    Chromosome  Start   End     Num_markers LogRatio
       Samp.1        6  14170000.5  26930000.5  309     0.393 
       Samp.1        7  50000.5     57690000.5  1411    -0.0486       
       Samp.1        13 19250000.5  83370000.5  1586    -0.5121"

df1 <-read.table(text=x, header=T, sep = "\t")



marK <- "Name   Chromosome  Position
7:50000.5       7   50000.5
7:57670000.5    7   57670000.5
6:14170000.5    6   14170000.5
6:26950000.5    6   26950000.5
6:36950000.5    6   36950000.5
13:19270000.5   13  19270000.5
13:83370000.5    13   83370000.5" 
marker <- read.table(text=marK, header=T)


expectedOutput <- "Sample  Chromosome  Start    End   Num_markers LogRatio
                    Samp.1   6     14170000.5   26950000.5  309   0.393    
                    Samp.1   7       50000.5    57670000.5  1411 -0.0486
                    Samp.1  13      19270000.5  83370000.5  1586    -0.5121"
llrs
  • 3,308
  • 35
  • 68
Kryo
  • 921
  • 9
  • 24
  • Maybe this post can help? http://stackoverflow.com/questions/24480031 Merge on overlap? – zx8754 Jun 07 '16 at 15:31
  • This appears to be a simple question on merging – alexwhitworth Jun 07 '16 at 16:05
  • Possible duplicate of [How to join (merge) data frames (inner, outer, left, right)?](http://stackoverflow.com/questions/1299871/how-to-join-merge-data-frames-inner-outer-left-right) – alexwhitworth Jun 07 '16 at 16:06
  • Your expected output is the same as `df1`. Please explain better what you are trying to achieve. – Jaap Jun 07 '16 at 17:29
  • If the values of Start and End column in df1 is not matching with Position column in marker, i want to replace it with the nearest Position value. in the above example, df1[1,4] doest not have any matching values in marker[,3], so it is replaces with the nearest values from marker[,3]. – Kryo Jun 07 '16 at 18:12

0 Answers0