I have a simple data frame with specifies start and end positions within lists. These start and end positions define i number of regions. Now I would like to test whether a given position lies within such a region and if yes I need to know in which region (i).
Here is a simple example data frame:
start <- list(c(5,10,15), c(5) ,c(6,11),c(6,11))
end <- list(c(7,11,17), c(10), c(8,12),c(8,12))
imax <- c(3,1,2,2)
position <- c(11,6,9,8)
example <- data.frame(start = I(start), end = I(end), imax = imax, position = position)
When I have only one start and end position it is no problem (as in row 2 of example):
data.table::between(example$position[[1]], example$start[[1]], example$end[[1]])
[1] FALSE TRUE FALSE
How can I turn this into a function which checks this pairwise for every element (from i=1 to i=max) within example$start and example$end?
The second step would be to retrieve for which region i (1 to imax) this was TRUE.
Thank you.