Skip to content

Instantly share code, notes, and snippets.

@aammd
Created December 5, 2016 14:16
Show Gist options
  • Save aammd/85a1a3bd4ca262359bee4495dc053a32 to your computer and use it in GitHub Desktop.
Save aammd/85a1a3bd4ca262359bee4495dc053a32 to your computer and use it in GitHub Desktop.
are a vector of range edges, separated by _, continuous?
## this function will print "TRUE" if the categories defined by the vector are
## continuous, e.g. c("1500_20000","20000_NA","0_1500" ) `
is_continuous_categories <- function(cat_vector){
cat_range <- cat_vector %>%
str_split("_") %>%
transpose %>%
map(unlist) %>%
{c(invoke(setdiff, .), invoke(setdiff, rev(.)))}
identical(cat_range, c("0", "NA"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment