# Packages ----------------------------------------------------------------
pacman::p_load(
rio, # for importing data
here, # for file paths
janitor, # for data cleaning
tidyverse, # for data management
reprex, #minimal repr example
datapasta #sample data
)
# Import Data -------------------------------------------------------------
surv_raw <- data.frame(
stringsAsFactors = FALSE,
check.names = FALSE,
case_id = c("694928","86340d","92d002",
"544bd1","6056ba","eb5aeb","e64e04","5a65bb","2ae019",
"7ca4c0"),
`onset date` = c("11/9/2014","10/30/2014",
"8/16/2014","8/29/2014","10/20/2014","10/28/2014",
"10/6/2014","9/21/2014","5/6/2014","9/29/2014"),
`date of report` = c("11/9/2014","10/31/2014",
"8/20/2014","8/30/2014","10/21/2014","11/1/2014",
"10/10/2014","9/22/2014","5/11/2014","9/30/2014")
)
# Cleaning Data -----------------------------------------------------------
surv <- surv_raw %>%
clean_names() %>%
select(case_id, onset_date, date_of_report) %>%
mutate(onset_date = ymd(onset_date)) %>%
mutate(date_of_report = 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.
print(surv)
#> case_id onset_date date_of_report
#> 1 694928 <NA> <NA>
#> 2 86340d <NA> <NA>
#> 3 92d002 <NA> <NA>
#> 4 544bd1 <NA> <NA>
#> 5 6056ba <NA> <NA>
#> 6 eb5aeb <NA> <NA>
#> 7 e64e04 <NA> <NA>
#> 8 5a65bb <NA> <NA>
#> 9 2ae019 <NA> <NA>
#> 10 7ca4c0 <NA> <NA>
Created on 2024-08-09 with reprex v2.1.1
Session info
sessionInfo()
#> R version 4.4.1 (2024-06-14 ucrt)
#> Platform: x86_64-w64-mingw32/x64
#> Running under: Windows 11 x64 (build 22631)
#>
#> Matrix products: default
#>
#>
#> locale:
#> [1] LC_COLLATE=English_Philippines.utf8 LC_CTYPE=English_Philippines.utf8
#> [3] LC_MONETARY=English_Philippines.utf8 LC_NUMERIC=C
#> [5] LC_TIME=English_Philippines.utf8
#>
#> time zone: Asia/Manila
#> tzcode source: internal
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] datapasta_3.1.0 reprex_2.1.1 lubridate_1.9.3 forcats_1.0.0
#> [5] stringr_1.5.1 dplyr_1.1.4 purrr_1.0.2 readr_2.1.5
#> [9] tidyr_1.3.1 tibble_3.2.1 ggplot2_3.5.1 tidyverse_2.0.0
#> [13] janitor_2.2.0 here_1.0.1 rio_1.2.1
#>
#> loaded via a namespace (and not attached):
#> [1] utf8_1.2.4 generics_0.1.3 stringi_1.8.4 hms_1.1.3
#> [5] digest_0.6.36 magrittr_2.0.3 evaluate_0.24.0 grid_4.4.1
#> [9] timechange_0.3.0 fastmap_1.2.0 rprojroot_2.0.4 fansi_1.0.6
#> [13] scales_1.3.0 cli_3.6.3 rlang_1.1.4 munsell_0.5.1
#> [17] withr_3.0.1 yaml_2.3.10 tools_4.4.1 tzdb_0.4.0
#> [21] colorspace_2.1-1 pacman_0.5.1 vctrs_0.6.5 R6_2.5.1
#> [25] lifecycle_1.0.4 snakecase_0.11.1 fs_1.6.4 pkgconfig_2.0.3
#> [29] pillar_1.9.0 gtable_0.3.5 glue_1.7.0 xfun_0.46
#> [33] tidyselect_1.2.1 rstudioapi_0.16.0 knitr_1.48 htmltools_0.5.8.1
#> [37] rmarkdown_2.27 compiler_4.4.1