Error code: All formats failed to parse

Hi R community,
I am getting the below error when trying to clean my dataset. Any help would be appreciated. Thanks in advance!

# REPREX 2

# install and load packages
pacman::p_load(rio, here, janitor, tidyverse, reprex, datapasta)

# import data
surv_raw <- import(here("data", "raw", "surveillance_linelist_20141201.csv"))
#> Error: No such file: C:/Users/z5253164/AppData/Local/Temp/RtmpKWPa78/reprex-721849b3691f-awake-topi/data/raw/surveillance_linelist_20141201.csv

# try to convert column to class "Date"
surv_clean <- data.frame(
  stringsAsFactors = FALSE,
       check.names = 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))
#> Error in eval(expr, envir, enclos): object 'surv_raw' not found

# check the CLEANED date column class and date range
class(surv_clean$onset_date)
#> [1] "NULL"
range(surv_clean$onset_date)
#> Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
#> Inf
#> Warning in max(x, na.rm = na.rm): no non-missing arguments to max; returning
#> -Inf
#> [1]  Inf -Inf
1 Like

Hi @d.honeyman , Your date is in mm-dd-yyyy format. Perhaps try mdy() instead of ymd() for date conversion?

1 Like