日期到 POSIXt 转换

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

我在 R 中有 2 个数据框(data_db、options_data),其中日期列的格式不同

这是日期格式的输出

data_db$CALENDAR_DT[1]

“1988-01-04 美国东部时间”

class(data_db$CALENDAR_DT[1])

“POSIXct”“POSIXt”

daily_options$CALENDAR_DT[1]

“2020-01-02”

class(daily_options$CALENDAR_DT[1])

“日期”

现在我想将 daily_options 中的整个日期列转换为与 data_db 相同的格式,以便我可以比较两列以执行左连接

我使用了以下方法

as.POSIXct(daily_options$CALENDAR_DT[2],format = "%Y-%m-%d",tz="America/New_York")

但这给出了结果

“2020-01-01 19:00:00 美国东部时间”

我需要修正什么

r datetime rbind
1个回答
0
投票

我认为这应该有效:

daily_options <- data.frame(CALENDAR_DT = as.Date("2020-01-02"))

daily_options$CALENDAR_DT <- as.POSIXct(daily_options$CALENDAR_DT, format = "%Y-%m-%d", tz = "America/New_York")
© www.soinside.com 2019 - 2024. All rights reserved.