如何将字符时间戳列转换为R中的日期时间对象

问题描述 投票:0回答:1

我有一个带有chr列的数据集,其格式为:

“” 2000-01-01 00:00:00 +0000 UTC“

如何将其转换为R中的日期时间对象?我尝试使用以下内容,但它给了我NAs。

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

r datetime posixct
1个回答
0
投票

我们可以使用ymd_hms

library(lubridate)
ymd_hms(str1)

数据

str1 <- "2000-01-01 00:00:00 +0000 UTC" 
© www.soinside.com 2019 - 2024. All rights reserved.