Created
October 15, 2020 20:08
-
-
Save seasmith/33d9b2612df792e42fbec77e4c104333 to your computer and use it in GitHub Desktop.
Extra SQL-like functions for dplyr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Symmetrical set-difference | |
# from: https://github.com/tidyverse/dplyr/issues/4811 | |
symdiff <- function(x, y) { | |
setdiff(union(x, y), intersect(x, y)) | |
} | |
# Inserting join | |
# from: https://github.com/tidyverse/dplyr/issues/1275 | |
insert <- function(data, insertData, by) { | |
data %>% | |
dplyr::anti_join(insertData, by = by) %>% | |
dplyr::bind_rows(insertData) %>% | |
dplyr::arrange_(.dots = by) | |
} | |
# Symmetrical anti-join | |
sym_anti_join <- function (x, y, by = NULL, copy = FALSE, ...) { | |
x_only <- anti_join(x, y, by = by, copy = copy, ...) | |
y_only <- anti_join(y, x, by = by, copy = copy, ...) | |
bind_rows(x_only, y_only) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment