hello, i have an issue with date as character, can not change class to date. Below i submite reprex. Thanks
# practice session module 6 -----------------------------------------------
# H7N9 data set
# date: 20241121
# fabio [email protected]
# load packages -----------------------------------------------------------
install.packages("pacman")
#>
#> The downloaded binary packages are in
#> /var/folders/vr/88w7r8d50rb7xbx_x8rx55640000gn/T//RtmpWJtijL/downloaded_packages
pacman::p_load(rio,
here,
janitor,
reprex,
datapasta,
epitrix,
flextable,
gtsummary,
scales,
viridis,
skimr,
lubridate,
tidyverse
)
# import data set ---------------------------------------------------------
inf_raw <- data.frame(
stringsAsFactors = FALSE,
date_of_symptoms = c("2/19/2013","2/27/2013",
"3/9/2013","3/19/2013","3/19/2013","3/21/2013","3/20/2013",
"3/7/2013","3/25/2013","3/28/2013")
)
# clean data --------------------------------------------------------------
infH7N9 <- inf_raw %>%
clean_names() %>% # clean names automatically
filter(province != "Anhui") %>% # remove Anhui from province
mutate(day_of_symptoms = as.Date(date_of_symptoms))
#> Error in `filter()`:
#> βΉ In argument: `province != "Anhui"`.
#> Caused by error:
#> ! object 'province' not found
#> Backtrace:
#> β
#> 1. ββ... %>% mutate(day_of_symptoms = as.Date(date_of_symptoms))
#> 2. ββdplyr::mutate(., day_of_symptoms = as.Date(date_of_symptoms))
#> 3. ββdplyr::filter(., province != "Anhui")
#> 4. ββdplyr:::filter.data.frame(., province != "Anhui")
#> 5. β ββdplyr:::filter_rows(.data, dots, by)
#> 6. β ββdplyr:::filter_eval(...)
#> 7. β ββbase::withCallingHandlers(...)
#> 8. β ββmask$eval_all_filter(dots, env_filter)
#> 9. β ββdplyr (local) eval()
#> 10. ββbase::.handleSimpleError(...)
#> 11. ββdplyr (local) h(simpleError(msg, call))
#> 12. ββrlang::abort(message, class = error_class, parent = parent, call = error_call)
#minimal data set
# inf_raw %>%
# head(10) %>%
# select(date_of_symptoms) %>%
# dpasta()
#
# data.frame(
# stringsAsFactors = FALSE,
# date_of_symptoms = c("2/19/2013","2/27/2013",
# "3/9/2013","3/19/2013","3/19/2013","3/21/2013","3/20/2013",
# "3/7/2013","3/25/2013","3/28/2013")
# )
Created on 2024-11-21 with reprex v2.0.2
Session info