'Having trouble converting chr to date [duplicate]
I have been trying to convert a column in a dataframe from chr to a date-time format in R using lubridate.
So far, I have tried:
minute_sleep <- minute_sleep %>%
clean_names() %>%
mutate(date = mdy_hms(date,tz=Sys.timezone())) %>%
separate(date, into = c("date", "time"), sep = " ")
and
minute_sleep <- minute_sleep %>%
clean_names() %>%
mutate(time = parse_date_time(time, "%m/%d/%Y %I:%M:%S %p")) %>%
separate(date, into = c("date", "time"), sep = " ")
The first method results in separate date and time columns but with both being type chr.
The second method returns an error.
Error in
mutate(): ! Problem while computingtime = parse_date_time(time, "%m/%d/%Y %I:%M:%S %p"). Caused by error inas.character(): ! cannot coerce type 'closure' to vector of type 'character'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
