Skip to content

Instantly share code, notes, and snippets.

@luisDVA
Created January 2, 2021 02:40
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 luisDVA/3019a0168c3b63627f190ecd29bdb1b1 to your computer and use it in GitHub Desktop.
Save luisDVA/3019a0168c3b63627f190ecd29bdb1b1 to your computer and use it in GitHub Desktop.
Working with columns using across
## %######################################################%##
# #
#### Working with columns with 'across' - Your Turn ####
# #
## %######################################################%##
# Load the midwest data bundled with ggplot2
# Keep only rows for Ohio (OH)
# Subset the 'county' column and all columns that match the string 'pop' (hint: use a selection helper)
# Square-root transform all numeric variables
# load packages -----------------------------------------------------------
library(ggplot2)
library(dplyr)
# load data ---------------------------------------------------------------
data("midwest")
# subset rows and columns -------------------------------------------------
midwest %>%
filter(state == "OH") %>%
select(county, matches("pop"))
# transform multiple variables --------------------------------------------
midwest %>%
filter(state == "OH") %>%
select(county, matches("pop")) %>%
mutate(across(where(is.numeric), sqrt))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment