I have a reference table where each row contains an interval (col1, col2) and 2 other values (color: "red", "blue", direction: "+", "-"), such as the below interv
interv1 <- cbind(seq(from = 3, to = 40, by = 4),seq(from = 5, to = 50, by = 5), c(rep("blue",5), rep("red", 5)), rep("+",10))
interv2 <- cbind(seq(from = 3, to = 40, by = 4),seq(from = 5, to = 50, by = 5), c(rep("blue",5), rep("red", 5)), rep("-",10))
interv <- rbind(interv1, interv2)
[,1] [,2] [,3] [,4]
[1,] "3" "5" "blue" "+"
[2,] "7" "10" "blue" "+"
[3,] "11" "15" "blue" "+"
[4,] "15" "20" "blue" "+"
[5,] "19" "25" "blue" "+"
[6,] "23" "30" "red" "+"
I also have a table of interest that has specific position included in intervals of the first table plus the color and direction variable.
to_match <- cbind(rep(seq(from = 4, to = 43, by = 4),2), rep(c(rep("blue", 5), rep("red", 5)), 2), c(rep("-", 10), rep("+", 10)))
[,1] [,2] [,3]
[1,] "4" "blue" "-"
[2,] "8" "blue" "-"
[3,] "12" "blue" "-"
[4,] "16" "blue" "-"
[5,] "20" "blue" "-"
[6,] "24" "red" "-"
What I would like to do is to associate to_match
values to the right interval when it has the same color and the same direction. The idea is to have something like this :
[,1] [,2] [,3] [,4] [5]
[1,] "3" "5" "blue" "+" "4"
or the opposite :
[,1] [,2] [,3] [4] [5]
[1,] "4" "blue" "-" "3" "6"
I started to try using the data.table::between()
function but it became a mess quite quickly... In my real dataset the to_match
columns is not the same length as interv
(not sure if this is relevant)