[R-SIG-Finance] timeSeries 2 zoo convert
Costas Vorlow
costas.vorlow at gmail.com
Tue Apr 17 19:27:17 CEST 2012
Hello,
What is the "best" way to convert an timeSeries object to .zoo?
Say I have the following timeSeries object:
> is(x)
[1] "timeSeries" "structure" "vector"
> head(x)
GMT
DAAA
1983-01-03 11.77
1983-01-04 11.79
1983-01-05 11.79
1983-01-06 11.74
1983-01-07 11.74
1983-01-10 11.75
>
When I try to convert it to zoo, I can not retain the dates info. I tried:
a<-as.Date(index( x ))
xz<-as.zoo(x)
index(xz)<-a
but dates change.
head(xz)
DAAA
1970-01-02 11.77
1970-01-03 11.79
1970-01-04 11.79
1970-01-05 11.74
1970-01-06 11.74
1970-01-07 11.75
This used to work with last year's libraries but it seems it doesn't anymore:
a<-index(as.zoo(x))
xz<-as.zoo(x)
xnew<-aggregate(xz, as.Date, identity)
Error in as.Date.default(index(x)) :
do not know how to convert 'index(x)' to class "Date"
Any help, extremely welcome.
thanks in advance,
Costas
> sessionInfo()
R version 2.13.0 (2011-04-13)
Platform: i386-pc-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United
States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] graphics grDevices datasets stats utils methods base
other attached packages:
[1] fImport_2110.79 timeSeries_2130.92
[3] timeDate_2130.93 fMarkovSwitching_1.0
[5] Rdonlp2_0.3-1 rcom_2.2-3.1
[7] rscproxy_1.3-1 quantmod_0.3-17
[9] TTR_0.21-0 Defaults_1.1-1
[11] PerformanceAnalytics_1.0.3.2 xts_0.8-2
[13] zoo_1.7-4
loaded via a namespace (and not attached):
[1] grid_2.13.0 lattice_0.19-33 tools_2.13.0
>
--
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|c|o|s|t|a|s|@|v|o|r|l|o|w|.|o|r|g|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
More information about the R-SIG-Finance
mailing list