[R-SIG-Finance] Replacing zoo time series values

Gabor Grothendieck ggrothendieck at gmail.com
Wed May 12 12:49:47 CEST 2010


Try

library(fImport)
library(zoo)
SPyf<-yahooSeries("^GSPC", file="SPyahoo.csv", frequency="daily", nDaysBack=400)
z <- as.zoo(SPyf)
z[,1] <- (z[,2]+z[,3])/2
colnames(z)[1]  <- "hilo"

See the three vignettes that come with zoo for many examples.  In
particular, vignette("zoo-quickref") illustrates the use of the
tseries package to read a series from yahoo directly into a zoo
object.  Also see the related quantmod and xts packages.

On Wed, May 12, 2010 at 4:33 AM, Research <risk2009 at ath.forthnet.gr> wrote:
> Hello,
>
> I am importing data, say S&P 500 from yahoo:
>
>    SPyf<-yahooSeries("^GSPC", file="SPyahoo.csv", frequency="daily",
> nDaysBack=400)
>    SPCOMPd<-(SPyf[,4])
>    a<-time(SPCOMPd)
>    SPd<-zoo(SPCOMPd,as.POSIXct(a))
>
> I am not sure if the above is correct but I am trying to convert a
> timeSeries object to zoo.
>
>> is(SPCOMPd)
> [1] "timeSeries" "structure"  "vector"
>>
>> is(SPd)
> [1] "zoo"
>
> I can do
>
> SPCOMPd[1]<-SPCOMPd[2]+SPCOMPd[3]
>
> with the timeseries object.
>
> Is it possible to do something like:
>
> SPd[1]<-(SPd[2]+SP[3])/2
>
> with the zoo object?
>
> I get:
>
> Error in SPd[1] <- (SPd[2] + SP[3])/2 : replacement has length zero
>
>
> Thanks in advance,
> Costas
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions
> should go.
>



More information about the R-SIG-Finance mailing list