【发布时间】:2019-04-03 01:42:51
【问题描述】:
我有一个名为“试用”的数据框。我已将数据框中的日期和时间组合在一起,以获得一个具有 POSIXct 时间戳的字段。我想将此组合日期时间或时间戳设置为我的数据框“试用”的索引,我该怎么做?我已经看到了类似的问题,但没有成功。 代码如下:
trial <- read.csv("2018_05_04_h093500.csv", header=TRUE, skip = 16, sep=",")
trial$Date <- with(trial, as.POSIXct(paste(as.Date(Date, format="%Y/%m/%d"), Time)))
dtPOSIXct <- as.POSIXct(trial$Date )
dtTime <- as.numeric(dtPOSIXct - trunc(dtPOSIXct, "days"))
class(dtTime) <- "POSIXct"
【问题讨论】:
-
可能是
format(Sys.time(), "%a_%b_%d_%Y")?不过你的问题还不清楚。 -
我希望时间戳作为数据帧的索引,就像在 python 中一样:trial.index=pd.to_datetime(trial.Date+" "+trial.Time