I have a dataset with a date variable:
2004/11/23 2022/8/1
So I rewrote them like this:
2004-11-23 2022-8-1
At this point class() returns "character". I have a problem converting this to "Date".
I tried:
df <- df %>%
mutate(
# rewrite / as -
date = gsub("/", "-", date)
) %>%
as.Date()
But the following error appreared:
Error in as.Date.default(.) :
do not know how to convert '.' to class “Date”
As far as I see, my rewritten variable (2004-11-23) does not have '.' Could anybody tell what is wrong with my code?
Without knowing much about your data, I think you're going to need to do this instead: