Created
January 2, 2021 02:40
-
-
Save luisDVA/3019a0168c3b63627f190ecd29bdb1b1 to your computer and use it in GitHub Desktop.
Working with columns using across
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## %######################################################%## | |
# # | |
#### 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