我想在类因子
中自动转换我的列(如下所示)Date.and.time..UTC.
2016-10-09 00:00:00+00:00
2016-10-09 00:10:00+00:00
2016-10-09 00:20:00+00:00
2016-10-09 00:30:00+00:00
2016-10-09 00:40:00+00:00
class(mdata$Date.and.time..UTC.)
[1] "factor"
到deux列:日期(班级日期)+时间(班级时间)
有可能吗?
目标是每天在午夜至早上6点之间删除。
答案 0 :(得分:0)
使用此数据:
df = read.table(text = "Date.and.time..UTC.
2016-10-09 00:00:00+00:00
2016-10-09 00:10:00+00:00
2016-10-09 00:20:00+00:00
2016-10-09 00:30:00+00:00
2016-10-09 00:40:00+00:00", header = T, sep = "\t")
as.Date
和as.POSIXct
工作得很好:
df$date = as.Date(df$Date.and.time..UTC.)
df$datetime = as.POSIXct(df$Date.and.time..UTC.)
df
# Date.and.time..UTC. date datetime
# 1 2016-10-09 00:00:00+00:00 2016-10-09 2016-10-09 00:00:00
# 2 2016-10-09 00:10:00+00:00 2016-10-09 2016-10-09 00:10:00
# 3 2016-10-09 00:20:00+00:00 2016-10-09 2016-10-09 00:20:00
# 4 2016-10-09 00:30:00+00:00 2016-10-09 2016-10-09 00:30:00
# 5 2016-10-09 00:40:00+00:00 2016-10-09 2016-10-09 00:40:00