Skip to content

Instantly share code, notes, and snippets.

@Nicktz
Last active May 3, 2016 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nicktz/2363d21d253663f61083f2185b0ada7c to your computer and use it in GitHub Desktop.
Save Nicktz/2363d21d253663f61083f2185b0ada7c to your computer and use it in GitHub Desktop.
SetNames allows a mutate function to design a formula and rename the new mutated column accordingly. It works perfectly well across vectors as well.
Another benefit is that setNames can then also be run to check the formula:
E.g. to create a % column for Variable:
Variable <- "FactorX"
DF %>%
mutate_(.dots =
setNames( paste0(Variable,"/sum(",Variable,", na.rm = TRUE))"), paste0(Variable, "Pct"))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment