Hi all, I’m working on cleaning some surveillance data. Here’s a small reproducible example — does this look good for checking date formats and ranges?
# install and load packages
pacman::p_load(
rio,
janitor,
here,
lubridate,
tidyverse,
datapasta,
reprex
)
# clean the surveillance data
demo_data <- data.frame(
stringsAsFactors = FALSE,
case_id = c("694928", "86340d", "92d002", "544bd1", "6056ba"),
onset_date = c("11/9/2014", "10/30/2014", "8/16/2014", "8/29/2014", "10/20/2014"),
sex = c("m", "f", "f", "f", "f")
)
demo_clean <- demo_data %>%
rename(date_onset = onset_date) %>%
mutate(date_onset = mdy(date_onset)) # use mdy() since your dates are in month/day/year format
# check class and range of date column
class(demo_clean$date_onset)
#> [1] "Date"
range(demo_clean$date_onset)
#> [1] "2014-08-16" "2014-11-09"
thanks all