Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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