想要将Time的类别更改为POSIXlt,并仅提取小时、分钟和秒钟
str(df3$Time)
chr [1:2075259] "17:24:00" "17:25:00" "17:26:00" "17:27:00" ...
使用了strptime函数
df33$Time <- strptime(df3$Time, format = "%H:%M:%S")
这将给出追加的日期/时间
> str(df3$Time)
POSIXlt[1:2075259], format: "2015-08-07 17:24:00" "2015-08-07 17:25:00" "2015-08-07 17:26:00" ...
想从POSIXlt类中提取时间,而不改变其类型。可以使用strftime函数。
df3$Time <- strftime(df3$Time, format = "%H:%M:%S")
但这将类转换回 "char" 类型 -
> class(df3$Time)
[1] "character"
我该如何仅提取类为POSIX或数字的时间?
as.integer(format(Sys.time(), "%H%M%S"))
可以很好地完成这个任务。请注意,这里不包括任何解释性的内容。 - Dirk Eddelbuettel