0
votes

I have a dataset with a chr column with the format:

"2000-01-01 00:00:00 +0000 UTC"

How do you convert it into a date-time object in R? I tried using the following but it is giving me NAs.

as.POSIXct(data$date, format="%y-%m-%d %H:%M:%S %z")

1
It's a FAQ. You need %Y for four digits years. Or use anytime::anytime() which requires no format string. - Dirk Eddelbuettel

1 Answers

0
votes

We can use ymd_hms

library(lubridate)
ymd_hms(str1)

data

str1 <- "2000-01-01 00:00:00 +0000 UTC"