I have a df like below and I am trying to convert the datettime column to a datetime format.
ID <- c("A","A","B","B")
datettime <- c("2015-12-03T13:04:06-06:00","2015-12-03T13:54:06-06:00","2015-12-03T16:04:06-06:00","2015-12-03T19:54:06-06:00")
df <- data.frame(ID,datettime)
the datettime column in my dataset is a character. I am trying to convert it to a datetime format but unable to get it right.
library(lubridate)
df$datettime <- ymd_hms(df$datettime)
#The problem here is the hours,minutes and seconds get messed up.
df$datettime <- as.POSIXct(df$datettime,format="%Y%m%d %H%M%S")
#This just ouputs NA's in the column
My desired output is
ID datettime
1 A 2015-12-03 13:04:06
2 A 2015-12-03 13:54:06
3 B 2015-12-03 16:04:06
4 B 2015-12-03 19:54:06
Any help would be appreciated.