Skip to content

Instantly share code, notes, and snippets.

@cbrown5
Created August 4, 2021 10:33
Show Gist options
  • Save cbrown5/56bd58e5ff82ba0c06e813a625a7268c to your computer and use it in GitHub Desktop.
Save cbrown5/56bd58e5ff82ba0c06e813a625a7268c to your computer and use it in GitHub Desktop.
scale numeric variables in a data.frame
#Apply scale to just numeric variables
#keep all variables
dat2 <- dat %>%
mutate(across(where(is.numeric), scale))
#keep just numerical variables, drop the others from the data.frame
dat2 <- dat %>%
transmute(across(where(is.numeric), scale))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment