I have a dataframe which generates dttm parsing errors. I tried different solutions but none worked after searching i found that dates records in one of the CSVs used to create the df is he root of the issue and I can't covert datatype to dates even after working on it seperately.
dput(head(df122020[,c("started_at","ended_at")]))
structure(list(started_at = c("07-12-21 15:06", "11-12-21 3:43",
"15-12-21 23:10", "26-12-21 16:16", "30-12-21 11:31", "01-12-21 18:28"
), ended_at = c("07-12-21 15:13", "11-12-21 4:10", "15-12-21 23:23",
"26-12-21 16:30", "30-12-21 11:51", "01-12-21 18:38")), row.names = c(NA,
-6L), class = c("tbl_df", "tbl", "data.frame"))
CodePudding user response:
It is in day, month, year, hour, minute format, use dmy_hm
from lubridate
library(dplyr)
library(lubridate)
df122020 <- df122020 %>%
mutate(across(c(started_at, ended_at), dmy_hm))
-output
> df122020
# A tibble: 6 × 2
started_at ended_at
<dttm> <dttm>
1 2021-12-07 15:06:00 2021-12-07 15:13:00
2 2021-12-11 03:43:00 2021-12-11 04:10:00
3 2021-12-15 23:10:00 2021-12-15 23:23:00
4 2021-12-26 16:16:00 2021-12-26 16:30:00
5 2021-12-30 11:31:00 2021-12-30 11:51:00
6 2021-12-01 18:28:00 2021-12-01 18:38:00