joshuaulrich / xts

Extensible time series class that provides uniform handling of many R time series classes by extending zoo.
http://joshuaulrich.github.io/xts/
GNU General Public License v2.0
219 stars 71 forks source link

Can't subset using a single specific time of day #238

Open ckatsulis opened 6 years ago

ckatsulis commented 6 years ago

xtsData.txt

Description

I was curious if sub-setting on a single time string should return the data point from each day where that time criteria is met.

Expected behavior

Much like subletting by a single date xtsData['2018-04-27'], I believe I have seen xtsData['T17:00:00'] work at certain points, but currently I am not able to get this to work on minute intervals.

Minimal, reproducible example

### Does Not Work
xtsData['T17:00:00']
     V1
### Works
xtsData['T17:00:00/T17:00:01']
                    V1
2018-02-01 17:00:00    0.8034
2018-02-02 17:00:00    0.7935
2018-02-05 17:00:00    0.7900
2018-02-06 17:00:00    0.7885
2018-02-07 17:00:00    0.7824
2018-02-08 17:00:00    0.7796
2018-02-09 17:00:00    0.7788
2018-02-12 17:00:00    0.7840
2018-02-13 17:00:00    0.7856
2018-02-14 17:00:00    0.7912

Session Info

R version 3.4.1 (2017-06-30)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.2 LTS

Matrix products: default
BLAS: /usr/lib/openblas-base/libblas.so.3
LAPACK: /usr/lib/libopenblasp-r0.2.18.so

locale:
 [1] LC_CTYPE=en_US.UTF-8          LC_NUMERIC=C                  LC_TIME=en_US.UTF-8           LC_COLLATE=en_US.UTF-8        LC_MONETARY=en_US.UTF-8       LC_MESSAGES=en_US.UTF-8       LC_PAPER=en_US.UTF-8         
 [8] LC_NAME=en_US.UTF-8           LC_ADDRESS=en_US.UTF-8        LC_TELEPHONE=en_US.UTF-8      LC_MEASUREMENT=en_US.UTF-8    LC_IDENTIFICATION=en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] FinancialInstrument_1.2.0 quantmod_0.4-10           TTR_0.23-1                rotoReuter_0.1.2          influxdbr_0.14.2          dygraphs_1.1.1.4          xts_0.10-2.1              zoo_1.8-1                

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.14               compiler_3.4.1             formatR_1.4                bitops_1.0-6               tools_3.4.1                testthat_1.0.2             digest_0.6.12              lubridate_1.7.2           
 [9] lattice_0.20-35            rlang_0.1.4                shiny_1.0.5                roll_1.0.7                 rJava_0.9-8                stringr_1.3.0              knitr_1.14                 xlsxjars_0.6.1            
[17] htmlwidgets_0.9            grid_3.4.1                 data.table_1.9.6           gsee_1.7-2                 R6_2.2.2                   RJSONIO_1.3-0              qmao_1.6.11                pander_0.6.0              
[25] purrr_0.2.4                magrittr_1.5               PerformanceAnalytics_1.5.2 htmltools_0.3.6            mime_0.5                   timeDate_3012.100          xtable_1.8-2               httpuv_1.3.5              
[33] quadprog_1.5-5             xlsx_0.5.7                 stringi_1.1.6              RcppParallel_4.3.20.2      RCurl_1.95-4.8             crayon_1.3.2               chron_2.3-47   
braverock commented 6 years ago

I think the answer to this is 'no'

Time based subsetting 'T09:00/T17:00' is not fully ISO-8601 compliant.

As I recall, in the ISO standard, the portion after the T is just to get to granularities of less than a day.

So xts's time of day subsetting is more an ISO-8601-style subset that makes a nod to how users generally want the data: accross all days, get the time subset I've specified.

Now getting back to why I think the answer is no.

If you specified just a single time, it isn't really a subset, but rather a single point in time. One what day? With what precision? what about time zone changes or daylight savings time?

So, my thoughts are that the current behavior is correct, and as I would expect it. I'm sure @joshuaulrich will have thoughts as well.