[R] unexpected behaviour of an extended time series (using packages spuRs and xts)

Joshua Ulrich josh.m.ulrich at gmail.com
Fri Jan 22 18:23:15 CET 2016


Try using the latest xts on GitHub:
https://github.com/joshuaulrich/xts

On Thu, Jan 14, 2016 at 9:05 AM, Olivier ETERRADOSSI
<olivier.eterradossi at mines-ales.fr> wrote:
> Hi list,
>
>
>
> I thought I knew how to use extended time series (package xts), but I was
> wrong  J  …
>
>
>
> While preparing a toy example for something else, using data provided in
> R, I run into an unexpected problem and can’t figure by myself what is
> happening below, can anyone of you tell ? I searched the archives but
> didn’t locate any answer. Probably it’s trivial, so please forgive  :
>
>
>
> I’m using :
>
> R version 3.2.3 (2015-12-10) -- "Wooden Christmas-Tree" / Platform:
> x86_64-w64-mingw32/x64 (64-bit)
>
> Packages are updated weekly, sometimes daily.
>
>
>
> I take some data from package spuRs :
>
>> library(spuRs)
>
>> data(kew)
>
>
>
> I turn the dataframe into time series (by combining each kew[,2:13] one
> after each other into a vector, and turning the vector into time series).
>
>
>
> One is ts :
>
>
>
>>
> kew.ts<-ts(data=stock,start=kew$year[1],end=kew$year[length(kew$year)],fre
> quency=12)
>
>
>
> And the other is xts, it looks fine at first :
>
>
>
>> kew.xts<-as.xts(kew.ts)
>
>> periodicity(kew.xts)
>
> Monthly periodicity from janv. 1697 to janv. 1999  # OK
>
>> hist(kew.xts) # OK
>
>> summary(kew.xts)
>
>      Index         kew.xts
>
>  Min.   :1697   Min.   :  0.00
>
>  1st Qu.:1772   1st Qu.: 29.70
>
>  Median :1848   Median : 47.00
>
>  Mean   :1848   Mean   : 51.14
>
>  3rd Qu.:1924   3rd Qu.: 67.60
>
>  Max.   :1999   Max.   :189.00  # OK
>
>
>
>> gdata::is.what(kew.xts)
>
> [1] "is.array"        "is.atomic"       "is.double"
> "is.index.unique"
>
> [5] "is.matrix"       "is.numeric"      "is.object"       "is.regular"
>
>
>  [9] "is.time.unique"  "is.unsorted"     "is.xts"          "is.zoo"
> # seems OK
>
>
>
>
>
> # But now, first try :
>
>> plot(kew.xts)
>
> Error in if (on == "years") { :
>
>   valeur manquante là où TRUE / FALSE est requis     # french for «
> missing value where TRUE/FALSE is required »
>
>
>
> # hmmmm, let’s try something else :
>
>> plot(kew.xts['1697-01/1979/']) # OK
>
>
>
>> plot(kew.xts['1697-01/1980/'])
>
> Error in if (on == "years") { :
>
>   valeur manquante là où TRUE / FALSE est requis
>
>
>
>> plot(kew.xts['1697-01/1979-12/']) # OK
>
>
>
>> plot(kew.xts['1697-01/1980-01/'])
>
> Error in if (on == "years") { :
>
>   valeur manquante là où TRUE / FALSE est requis
>
>
>
> # but…!  :
>
>
>
>> plot(kew.xts['1979-01/1980/']) # OK !!!!!
>
>
>
> And so are :
>
>> plot (kew.xts['1978/1980/'])
>
>> plot(kew.xts['1977/1982/'])
>
>> plot(kew.xts['1977-01/1982-12'])  # and so on…
>
>
>
> I’m puzzled ! I have probably missed a trivial point… Can someone tell ?
>
>
>
> Thanks a lot list, regards, Olivier
>
>
>
> --------------------------
>
> Olivier ETERRADOSSI
>
> Maître-Assistant, HDR
>
> Ecole des Mines d’Alès (C2MA, site de Pau)
>
> Ingénierie de l'aspect visuel et tactile des matériaux
>
> Pôle « Recherche sur les Interactions des Matériaux avec leur
> Environnement » (RIME)
>
> Hélioparc, 2 av. P. Angot, F-64053 PAU CEDEX 9
>
> Tel : 05 59 30 90 35 (direct) - 05 59 30  54 25 (std)
>
> Fax : 05 59 30 63 68
>
>  <http://www.mines-ales.fr/> http://www.mines-ales.fr
>
>  <http://www.mines-telecom.fr/> http://www.mines-telecom.fr
>
>
>
>
>
>
>
>
>         [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com
R/Finance 2016 | www.rinfinance.com



More information about the R-help mailing list