Skip to content

Instantly share code, notes, and snippets.

@charliejhadley
Created May 11, 2022 16:36
Show Gist options
  • Save charliejhadley/33132f65302e731afbfd697e46c42563 to your computer and use it in GitHub Desktop.
Save charliejhadley/33132f65302e731afbfd697e46c42563 to your computer and use it in GitHub Desktop.
parse-number.R
data_2020 <- tibble(
id = 1:4,
wk1 = c(1, "-", NA, 4),
wk2 = c(1, "-", 3, 4)
)
data_2021 <- tibble(
id = 1:4,
wk1 = c(1, NA, 3, 4),
wk2 = c(1, 2, 3, 4)
)
wrangle_data <- function(data){
data %>%
pivot_longer(contains("wk")) %>%
mutate(value = parse_number(value))
}
data_2020 %>%
wrangle_data()
data_2021 %>%
wrangle_data()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment