我有以下时间序列:
library (zoo)
ts1 <- "f,c
1,19/11/2014 12:00,0.01
2,19/11/2014 13:00,0.01
3,20/11/2014 15:00,0.01
4,20/11/2014 16:00,0.01
5,20/11/2014 17:00,0.01
6,20/11/2014 19:00,0.01
7,20/11/2014 22:00,0.20
8,20/11/2014 23:00,0.03
9,21/11/2014 16:00,0.01
10,21/11/2014 17:00,0.01"
z <- read.zoo(text = ts1, tz = "", format = "%d/%m/%Y %H:%M", sep = ",")
我想创建一个新的动物园 - z1
,它将成为z的子集,其中包含20/11/2014 15:00
到20/11/2014 23:00
的时间范围。它将包括以下内容:
3,20/11/2014 15:00,0.01
4,20/11/2014 16:00,0.01
5,20/11/2014 17:00,0.01
6,20/11/2014 19:00,0.01
7,20/11/2014 22:00,0.20
8,20/11/2014 23:00,0.03
答案 0 :(得分:1)
library(lubridate)
window(z, start = parse_date_time("20/11/2014 15:00", orders = "%d-%m-%Y H!:M!"),
end = parse_date_time("20/11/2014 23:00", orders = "%d-%m-%Y H!:M!"))