Training module 10, I tried to clean my date column but all the values were converted to NA. Any help is greatly appreciated. Reprex is below
# install and load packages
pacman::p_load(rio, datapasta, janitor, reprex, tidyverse, here)
# data
surv_raw <- data.frame(
stringsAsFactors = FALSE,
case_id = c("694928","86340d","92d002","544bd1","6056ba"),
sex = c("m", "f", "f", "f", "f"),
onset_date = c("11/9/2014","10/30/2014","8/16/2014","8/29/2014","10/20/2014")
)
# try to convert column to class "Date"
surv_clean <- surv_raw %>%
clean_names() %>%
mutate(onset_date = ymd(onset_date))
#> Warning: There was 1 warning in `mutate()`.
#> ℹ In argument: `onset_date = ymd(onset_date)`.
#> Caused by warning:
#> ! All formats failed to parse. No formats found.
# check the CLEANED date column class and date range
class(surv_clean$onset_date)
#> [1] "Date"
range(surv_clean$onset_date)
#> [1] NA NA
Created on 2024-03-08 with reprex v2.0.2
Session info
sessionInfo()
#> R version 4.3.1 (2023-06-16 ucrt)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 19045)
#>
#> Matrix products: default
#>
#>
#> locale:
#> [1] LC_COLLATE=English_United Kingdom.utf8
#> [2] LC_CTYPE=English_United Kingdom.utf8
#> [3] LC_MONETARY=English_United Kingdom.utf8
#> [4] LC_NUMERIC=C
#> [5] LC_TIME=English_United Kingdom.utf8
#>
#> time zone: Europe/London
#> tzcode source: internal
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] here_1.0.1 lubridate_1.9.2 forcats_1.0.0 stringr_1.5.0
#> [5] dplyr_1.1.2 purrr_1.0.1 readr_2.1.4 tidyr_1.3.0
#> [9] tibble_3.2.1 ggplot2_3.4.2 tidyverse_2.0.0 reprex_2.0.2
#> [13] janitor_2.2.0 datapasta_3.1.0 rio_0.5.29
#>
#> loaded via a namespace (and not attached):
#> [1] utf8_1.2.3 generics_0.1.3 stringi_1.7.12 hms_1.1.3
#> [5] digest_0.6.33 magrittr_2.0.3 evaluate_0.21 grid_4.3.1
#> [9] timechange_0.2.0 fastmap_1.1.1 rprojroot_2.0.3 cellranger_1.1.0
#> [13] zip_2.3.0 fansi_1.0.4 scales_1.2.1 cli_3.6.1
#> [17] rlang_1.1.1 munsell_0.5.0 withr_2.5.0 yaml_2.3.7
#> [21] tools_4.3.1 tzdb_0.4.0 colorspace_2.1-0 pacman_0.5.1
#> [25] curl_5.0.1 vctrs_0.6.3 R6_2.5.1 lifecycle_1.0.3
#> [29] snakecase_0.11.0 fs_1.6.3 foreign_0.8-84 pkgconfig_2.0.3
#> [33] pillar_1.9.0 openxlsx_4.2.5.2 gtable_0.3.3 data.table_1.14.8
#> [37] glue_1.6.2 Rcpp_1.0.11 haven_2.5.3 xfun_0.39
#> [41] tidyselect_1.2.0 rstudioapi_0.15.0 knitr_1.43 htmltools_0.5.7
#> [45] rmarkdown_2.23 compiler_4.3.1 readxl_1.4.3