Skip to content
Prev 6115 / 15274 Next

Replacing zoo time series values

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