Domanda

Non riesco a query XTS per sottoinsiemi tra cui un intervallo di data e tempo. Per esempio:

> head(myxts['2012-01-06 9:30:00/2012-01-06 10:00:00'], 1)
                    Symbol       
2012-01-03 09:30:00 "AA"

> tail(myxts['2012-01-06 9:30:00/2012-01-06 10:00:00'], 1)
                Symbol       
2012-01-06 10:00:00 "AA"

Qui la prima riga è 2012-01-03. Perché non 2012-01-06?

MODIFICARE

Ho anche provato a estrarre prima una singola data in una nuova variabile, quindi query per tempo. In questo caso le tempeste di data vengono estratte correttamente ma il sottoinsieme non funzionerà.

e = myxts['2012-01-06']
e['10:00:00::10:20:00'] # returns all rows in '2012-01-06'

EDIT 2

Ho trovato questa situazione in cui entrare in '09: 45: 00 'anziché' 9:45:00 'sembra risolvere il problema:

> tail(myxts['2011-12-19 9:40:00::2011-12-19 9:45:00'])
                    Symbol DaySec
2011-12-19 16:00:00 "WPI"  "57600"

> tail(myxts['2011-12-19 9:40:00::2011-12-19 09:45:00'])
                    Symbol DaySec  
2011-12-19 09:45:00 "WPI"  "35100"
È stato utile?

Soluzione

'2012-01-06 9:30:00' non è una stringa conforme ISO-8601. Ogni componente temporale deve essere due cifre (se specificato), quindi è necessario '2012-01-06 09:30:00'.

Altri suggerimenti

Per me va bene:

R> now <- Sys.time()
R> foo <- xts(1:100, now + (1:100)*30*60)   # hundred half-hour intervals
R> head(foo)
                          [,1]
2012-02-21 11:48:32.37683    1
2012-02-21 12:18:32.37683    2
2012-02-21 12:48:32.37683    3
2012-02-21 13:18:32.37683    4
2012-02-21 13:48:32.37683    5
2012-02-21 14:18:32.37683    6
R> tail(foo)
                          [,1]
2012-02-23 10:48:32.37683   95
2012-02-23 11:18:32.37683   96
2012-02-23 11:48:32.37683   97
2012-02-23 12:18:32.37683   98
2012-02-23 12:48:32.37683   99
2012-02-23 13:18:32.37683  100

Ora possiamo estrarre dall'ultima ora il 21 febbraio fino al primo il 23 febbraio:

R> xtract <- foo["2012-02-21 23:00::2012-02-23 01:00"]
R> head(xtract)
                          [,1]
2012-02-21 23:18:32.37683   24
2012-02-21 23:48:32.37683   25
2012-02-22 00:18:32.37683   26
2012-02-22 00:48:32.37683   27
2012-02-22 01:18:32.37683   28
2012-02-22 01:48:32.37683   29
R> tail(xtract)
                          [,1]
2012-02-22 22:18:32.37683   70
2012-02-22 22:48:32.37683   71
2012-02-22 23:18:32.37683   72
2012-02-22 23:48:32.37683   73
2012-02-23 00:18:32.37683   74
2012-02-23 00:48:32.37683   75
R> 

Posso anche estrarre in un giorno:

R> xtract <- foo["2012-02-23 02:00::2012-02-23 04:00"]
R> xtract
                          [,1]
2012-02-23 02:18:32.37683   78
2012-02-23 02:48:32.37683   79
2012-02-23 03:18:32.37683   80
2012-02-23 03:48:32.37683   81
R> 
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top