Arithmetic operations on zoo first cause a merge to occur, which will align
time.

You haven't provided a simple example to run, but you are likely getting a
zero-width zoo object (empty) back from your call:

> (GSPC[2]+GSPC[3])/2
     GSPC.Open GSPC.High GSPC.Low GSPC.Close GSPC.Volume GSPC.Adjusted

So the error is correct.

What you need to do is force one of the objects to be numeric.  And likely
the result as well:

> (GSPC[2]+as.numeric(GSPC[3]))/2
           GSPC.Open GSPC.High GSPC.Low GSPC.Close GSPC.Volume GSPC.Adjusted
2007-01-04   1417.47   1420.09  1407.09   1414.025  2961930000      1414.025


HTH
Jeff




On Wed, May 12, 2010 at 3:33 AM, Research <risk2009@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@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.
>



-- 
Jeffrey Ryan
jeffrey.ryan@insightalgo.com

ia: insight algorithmics
www.insightalgo.com

	[[alternative HTML version deleted]]

