Skip to content

Instantly share code, notes, and snippets.

@rkingdc
Created February 28, 2019 20:43
Show Gist options
  • Save rkingdc/e5bca600d06cbb07463b7ac54a5ae043 to your computer and use it in GitHub Desktop.
Save rkingdc/e5bca600d06cbb07463b7ac54a5ae043 to your computer and use it in GitHub Desktop.
Binning Columns in Remote Tables" dplyr join function
db_dplyr_join_fn <- function(data, tbl_cuts, column_to_cut="column_to_cut"){
bin_choices <- data %>%
select(., id, k_dummy, !!rlang::sym(column_to_cut)) %>%
left_join(., tbl_cuts, by = 'k_dummy') %>%
filter(., cut >= !!rlang::sym(column_to_cut)) %>%
group_by(., id) %>%
summarise(., cut_ = min(cut, na.rm = TRUE))
return(dplyr::compute(dplyr::left_join(data, bin_choices, by = 'id')))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment