Skip to content

Instantly share code, notes, and snippets.

@dreidpath
Created June 8, 2021 01:09
Show Gist options
  • Save dreidpath/acaa43756ccc48bc089f941a8bd1ff2e to your computer and use it in GitHub Desktop.
Save dreidpath/acaa43756ccc48bc089f941a8bd1ff2e to your computer and use it in GitHub Desktop.
#' In a dataframe, find all variable names that match var_pattern
#'
#' @param var_pattern a character string ("pattern" to match)
#' @param dframe a dataframe
#'
#' @return all variable names in the dataframe that match var_pattern
#' @export
#'
#' @examples
#' find_var(iris, "idth")
#' find_var(iris, ".")
#'
find_varname <- function(dframe, var_name){
names(dframe)[grepl(var_name, names(dframe))]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment