Subsetting a large zoo object using window() drops times
<p>Preamble: I have a large multi-variate zoo object. It contains several years of 60 minute interval data. I like to keep my data in large chunks and subset from the large chunk as I need to perform work. Normally, I'm doing prety basic stuff like just making graphs, but I'd like to move towards a deeper understanding of my data.</p>

<p>So. I'm taking my large data.csv file <a href="https://www.dropbox.com/s/2547dqa1kfyfilk/data.csv?dl=0" rel="nofollow">here</a>. And doing the following:</p>

<pre><code>library(zoo)
library(lubridate)
df &lt;- read.csv(file.choose(), na.strings = "")
df$FLOW &lt;- as.numeric(df$FLOW) # read.csv turns this row into a factor due to NAs.
df$NST_DATI &lt;- mdy_hm(df$NST_DATI, tz = "UTC")
df.zoo &lt;- read.zoo(df)
</code></pre>

<p>Say I want to subset this big chunk to only data from 2012. If I subset the df data.table I get this (Note that the times start at 2012-01-01 00:30:00, as expected):</p>

<pre><code>&gt; head(df[format(df$NST_DATI, "%Y") == 2012, ])
                 NST_DATI WATER_TEMP   PH SPEC_CONDUCT    DO PER_SATUR TURBIDITY    TDS  STAGE FLOW
35065 2012-01-01 00:30:00       0.82 6.48         40.3 13.24      92.5       2.6 0.0258 83.315  587
35066 2012-01-01 01:30:00       0.83 6.48         40.2 13.17      92.1       3.2 0.0257 83.313  585
35067 2012-01-01 02:30:00       0.85 6.44         40.1 13.11      91.8       3.8 0.0256 83.313  585
35068 2012-01-01 03:30:00       0.84 6.48         40.2 13.14      91.9       2.9 0.0257 83.313  585
35069 2012-01-01 04:30:00       0.86 6.48         40.2 13.10      91.7       2.9 0.0257 83.313  585
35070 2012-01-01 05:30:00       0.87 6.48         40.2 13.08      91.5       2.9 0.0257 83.312  583
</code></pre>

<p>When I subset using the <code>window()</code> function, I get a different result (Note that the times start at 2012-01-01 03:30:00).</p>

<pre><code>head(window(df.zoo, start = "2012-01-01", end = "2012-12-31"))
                    WATER_TEMP   PH SPEC_CONDUCT    DO PER_SATUR TURBIDITY    TDS  STAGE FLOW
2012-01-01 03:30:00       0.84 6.48         40.2 13.14      91.9       2.9 0.0257 83.313  585
2012-01-01 04:30:00       0.86 6.48         40.2 13.10      91.7       2.9 0.0257 83.313  585
2012-01-01 05:30:00       0.87 6.48         40.2 13.08      91.5       2.9 0.0257 83.312  583
2012-01-01 06:30:00       0.90 6.48         40.3 13.09      91.7       2.9 0.0258 83.312  583
2012-01-01 07:30:00       0.94 6.49         40.3 13.01      91.3       2.9 0.0258 83.313  585
2012-01-01 08:30:00       0.95 6.46         41.3 12.98      91.1       2.8 0.0264 83.316  588
</code></pre>

<p>It's really grinding my gears as I can reproduce it for other years, too. Thanks for any insight!</p>