1
我想基於時間子集數據幀:你如何子集的數據幀基於小時,分鐘,秒鐘的最有效的方式
df
Hostname Date cpu
Server101 1/1/2015 00:00:00 10
Server101 1/1/2015 00:00:00 10
Server101 1/1/2015 08:00:00 10
Server101 1/1/2015 06:00:00 10
我需要從09:00獲取數據: 00至17:00:00
所以這是我做的:
library(lubridate)
df<-transform(df, time= format(df$Date,'%H:%M:%S'))
df$time<-times(df$time)
df<-subset(df, time>times(c("09:00:00")) & time<times(c("17:00:00"")))
子功能的子集基於時間走的是一條很長的時間才能完成。有沒有更好的方法來做到這一點,最快?
你是否在格式化步驟之前轉換爲'Date'類 – akrun
@akrun,是日期是as.POSIXct – user1471980
數據集有多大 – akrun