r - Find correspondent numbers in integer intervals -
i correspondent numbers between 2 integers intervals. input that:
start1 end1 start2 end2 20 30 25 35 25 35 20 30 100 190 126 226 126 226 100 190
in first , second line, overlap first(1) interval (2 first collumns) second(2) interval (2 last collumns) equal 6 correspondents numbers (25,26,27,28,29 , 30).
my expected output that:
start1 end1 start2 end2 bp_overlapped 20 30 25 35 6 25 35 20 30 6 100 190 126 226 65 126 226 100 190 65
it matrix in r.
thank you.
the function searching intersect. can if x
first matrix:
f <- function(x) length( intersect(seq(x[1],x[2],1), seq(x[3],x[4],1)) ) <- apply(x,1,f) x <- cbind(x,a)
the function apply
applies function on each row of matrix (if second argument 1) or on each column (if second argument 2).
Comments
Post a Comment