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"