I am facing a weird situation with lubridate::as_date() inside a mutate Dplyr function.
I am trying to change dates from an Excel format to a date format.
The format I have is "45369", and I am trying to change the today column to "yyyy-mm-dd".
Taking into consideration the column can be any column in the data, the user will pick the name of the column through use input and be saved as [date_dc <- "user_input"].
Now, trying this format:
raw.main <- raw.main %>%
dplyr::mutate_at(vars(date_dc), ~ifelse(is.na(.), NA,lubridate::as_date(as.numeric(.), origin = "1899-12-30")))
return 19800 in all the column
Through a direct assignment, it returns:
raw.main[[date_dc]] <- lubridate::as_date(as.numeric(raw.main[[date_dc]]), origin = "1899-12-30")
Any idea what is the issue here?
Abraham
Sorry, was trying to upload more images, but I am a new user and posit didn't let me.
That's fine — sharing mock data that replicates the issue is actually better since it can help to highlight both misunderstanding and what might be going wrong. Thanks for sharing it.