prefix_replace function

prefix_replace

prefix_replace

Replace series of characters (usually variable names) at the beginning of a character vector.

prefix_replace(var_names, prefixes, replacements, toTitle = TRUE, ...)

Arguments

  • var_names: A character vector, usually variable names
  • prefixes: A character vector, usually variable prefixes
  • replacements: A character vector of replacements for the prefixes, in the same order as them.
  • toTitle: Convert results to Title Case? Defaults to TRUE.
  • ...: Other arguments to gsub

Returns

A character vector with prefixes terms in var_names replaced with the content of the replacement terms.

Details

Takes a character vector (usually vector of variable names from a summarized or tidied model object), along with a vector of character terms (usually the prefix of a dummy or categorical variable added by R when creating model terms) and strips the latter away from the former. Useful for quickly cleaning variable names for a plot.

Examples

prefix_replace(iris$Species, c("set", "ver", "vir"), c("sat", "ber", "bar"))

Author(s)

Kieran Healy

  • Maintainer: Kieran Healy
  • License: MIT + file LICENSE
  • Last published: 2020-06-10