我的数据是这样的:
structure(list(Date = structure(c(1509408000, 1509408000, 1509408000,
1509408000, 1509408000, 1509408000), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), Time = structure(c(-2208988860, -2208988920,
-2208988980, -2208989040, -2208989100, -2208989160), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), O = c(54.62, 54.62, 54.62, 54.62,
54.63, 54.63), H = c(54.63, 54.63, 54.62, 54.62, 54.63, 54.63
), L = c(54.62, 54.62, 54.62, 54.62, 54.62, 54.62), C = c(54.62,
54.62, 54.62, 54.62, 54.62, 54.62), date.time = structure(c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), class = c("POSIXct",
"POSIXt"), tzone = "")), row.names = c(NA, -6L), class = c("tbl_df",
"tbl", "data.frame"))
我希望时间要么与“日期”列中的日期相同,要么根本没有日期。 对于第一个解决方案,我尝试从Date列中获取日期,并从Time列中获取时间来创建datetime列。
我尝试了以下代码:
data_frame2$date.time <- as.POSIXct(paste0(data_frame2$Date, data_frame2$Time), format="%Y-%m-%d %H:%M:%S")
但是我在创建的date.time列中得到了NA。
我也尝试过用以下方法消除日期:
data_frame2_date_filter$Time <- format(ymd_hms(data_frame2_date_filter$Time), "%H:%M:%S")
atr_results$Time <- parse_date_time(atr_results$Time, "HMS")
atr_results$Time <- times(strftime(atr_results$Time, format="%H:%M:%S"))
但是这些也不起作用。