Skip to content

Instantly share code, notes, and snippets.

@TimTeaFan
Created April 22, 2021 17:25
Show Gist options
  • Save TimTeaFan/1edd8772b44e3a4cab25bae765a03ca3 to your computer and use it in GitHub Desktop.
Save TimTeaFan/1edd8772b44e3a4cab25bae765a03ca3 to your computer and use it in GitHub Desktop.
use where in select and across with custom function
library(tidyverse)
contains_comma <- function(x) {
if (is.character(x) || is.factor(x)) {
any(str_detect(x, ","))
} else {FALSE}
}
gss_cat %>%
select(where(contains_comma))
gss_cat %>%
transmute(across(where(contains_comma)))
gss_cat %>%
mutate(across(where(contains_comma)),
.keep = "none")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment