您可以xts
用于时间序列分析。xts
提供了对时间序列数据进行子集化的便捷方法。为了。例如。
txt <- '1995-10-13 04:00:00 460.5
1995-10-13 05:00:00 549.9
1995-10-13 06:00:00 648.8
1995-10-13 07:00:00 684.4
1995-10-13 08:00:00 652.3
1995-10-13 09:00:00 629.8
1995-10-13 10:00:00 582.6
1995-10-13 11:00:00 565.5
1995-10-13 12:00:00 543.5
1995-10-13 13:00:00 542.8'
DF <- read.table(text = txt, stringsAsFactors = FALSE)
xts(DF$V3, as.POSIXct(paste(DF$V1, " ", DF$V2)))
## [,1]
## 1995-10-13 04:00:00 460.5
## 1995-10-13 05:00:00 549.9
## 1995-10-13 06:00:00 648.8
## 1995-10-13 07:00:00 684.4
## 1995-10-13 08:00:00 652.3
## 1995-10-13 09:00:00 629.8
## 1995-10-13 10:00:00 582.6
## 1995-10-13 11:00:00 565.5
## 1995-10-13 12:00:00 543.5
## 1995-10-13 13:00:00 542.8
XTS <- xts(DF$V3, as.POSIXct(paste(DF$V1, " ", DF$V2)))
XTS
## [,1]
## 1995-10-13 04:00:00 460.5
## 1995-10-13 05:00:00 549.9
## 1995-10-13 06:00:00 648.8
## 1995-10-13 07:00:00 684.4
## 1995-10-13 08:00:00 652.3
## 1995-10-13 09:00:00 629.8
## 1995-10-13 10:00:00 582.6
## 1995-10-13 11:00:00 565.5
## 1995-10-13 12:00:00 543.5
## 1995-10-13 13:00:00 542.8
XTS["T10:00:00/T15:00:00"]
## [,1]
## 1995-10-13 10:00:00 582.6
## 1995-10-13 11:00:00 565.5
## 1995-10-13 12:00:00 543.5
## 1995-10-13 13:00:00 542.8