简体   繁体   中英

Select time range from zoo time series

I have the following time series:

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 = ",")

I would like to create a new zoo - z1 that will be subset of z that will include the time range 20/11/2014 15:00 till 20/11/2014 23:00 . It will include the following:

    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
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!"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM