I need to run an analysis from 10AM to 4PM. The original data runs from 9 AM to 5 PM, everyday for one year. How to include only the indicated time period for analysis ?
window in zoo does not help for the same.
structure(c(0, 7.12149266486255e-05, 0.000142429853297251, 0.000213644779945877, 0.000284859706594502, 0.000356074633243128, 0.000427289559891753, 0.000498504486540379, 0.000569719413189004, 0.00064093433983763, 0.000712149266486256, 0.000783364193134881, 0.000854579119783507, 0.000925794046432132, 0.000997008973080758, 0.00106822389972938, 0.00113943882637801, 0.00121065375302663, 0.00128186867967526, 0.00135308360632389, 0.00142429853297251, 0.00149551345962114, 0.00156672838626976, 0.00163794331291839, 0.00170915823956701, 0.00178037316621564, 0.00185158809286426, 0.00192280301951289, 0.00199401794616152, 0.00206523287281014), index = structure(c(1009942620, 1009942680, 1009942740, 1009942800, 1009942860, 1009942920, 1009942980, 1009943040, 1009943100, 1009943160, 1009943220, 1009943280, 1009943340, 1009943400, 1009943460, 1009943520, 1009943580, 1009943640, 1009943700, 1009943760, 1009943820, 1009943880, 1009943940, 1009944000, 1009944060, 1009944120, 1009944180, 1009944240, 1009944300, 1009944360), class = c("POSIXct", "POSIXt")), class = "zoo")
How to select periods of time > 10 AM and time < 4 PM, across several days.
If z is the zoo object then
1) use this to extract hour of each time point and then subset to only those that are 10, 11, 12, 13, 14 or 15.
z[format(time(z), "%H") %in% 10:15]
2) or use this alternative which is similar but uses POSIXlt to get the hour:
z[as.POSIXlt(time(z))$hour %in% 10:15]
3) or convert the series to xts and use this:
x <- as.xts(z)["T10:00/T15:00"]
drop(as.zoo(x))
Omit the second line if it is ok to return an xts series.
Be sure that you have the time zone set correctly since the time in one time zone is not the same as in another time zone.
We can query the current time zone of the session like this:
Sys.timezone()
and can set it like this:
Sys.setenv(TZ = "...")
where ... is replaced with the time zone desired. Common settings are:
Sys.setenv(TZ = "GMT")
Sys.setenv(TZ = "") # restore default
The following will show the possible time zones that can be used:
OlsonNames()
You only need all this if the time zone of your session is not already set to the time zone of the data.