Reprex Exemple 2 – Formats failed

Hello. I’m a new to R and struggling when use mutate to clean the onset date. I’m getting a warning message saying ”All formats failed to parse. Can’t figure out what cause this error. Any help would be appreciated. Thank you in advance

Hello. I’m a new R user and IM, struggling when use mutate to clean the onset date. I’m getting a warning message saying ”All formats failed to parse. Can’t figure out what cause this error. Any help would be appreciated. Thank you in advance

install and load packages

pacman::p_load(
rio,
here,
janitor,
reprex,
datapasta,
tidyverse)

import data

surv_raw ← data.frame(
stringsAsFactors = FALSE,
check.names = FALSE,
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”),
sex = c(“m”,“f”,
“f”,“f”,“f”,“f”,“f”,“m”,“m”,“m”),
case_id = c(“694928”,
“86340d”,“92d002”,“544bd1”,“6056ba”,
“eb5aeb”,“e64e04”,“5a65bb”,“2ae019”,“7ca4c0”))

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().
#> :information_source: In argument: onset_date = ymd(onset_date).
#> Caused by warning:
#> ! All formats failed to parse. No formats found.

1 Like

Hello,

You used the ymd function which requires your dates to be in the form YYYY-mm-dd, which they are not. Instead, you should use the mdy function to match the form of your dates.

All the best,

Tim