我曾经使用packagecombn()来查找两个日期/时间之间的重叠。但处理我正在处理的大型数据集太慢了。我正在尝试从包中使用,但无法让它工作。任何帮助,将不胜感激。如果您知道我应该查看的任何其他包/功能,也请告诉我。lubridatecombn()comboGeneral()RcppAlgos
get_overlap <- function(.data, .id, .start, .end) {
id <- .data[[.id]]
int <- interval(.data[[.start]], .data[[.end]])
names <- combn(id, 2, FUN = function(.) paste(., collapse = "-"))
setNames(combn(int, 2, function(.) intersect(.[1], .[2])), names)
}
get_overlap(dat, "id", "start", "end")
# a-b a-c a-d a-e b-c b-d b-e c-d c-e d-e
# 49 1 4 17 23 14 18 NA 2 NA
Run Code Online (Sandbox Code Playgroud)
这是我使用失败的尝试comboGeneral()。
comboGeneral(dat$int, 2, FUN = function(.) intersect(.[1], .[2]))
# Output: …Run Code Online (Sandbox Code Playgroud)