See ?lag and ?lag.xts

Time series objects like xts and zoo always align by time before doing
operations such as comparisons and arithmetic.

Your approach is a reasonable one, just not as simple or safe as using lag.

HTH
Jeff

On Sat, Jul 24, 2010 at 5:03 AM, Raghu <r.raghuraman@gmail.com> wrote:

> As a follow-up I am able to achieve this by coercing just the Open column
> into a numeric vector. But I am curious if I could do this without this
> workaround. Is there a way to directly compare two elements in an xts
> object
> ?
>
> Many thanks
> Raghu
>
> On Sat, Jul 24, 2010 at 10:55 AM, Raghu <r.raghuraman@gmail.com> wrote:
>
> > Hi
> >
> > I am trying to compare two elements in an xts object. Is the following
> way
> > wrong? Prices contain data of a price series. Thx for the help.
> >
> >
> > > prices$Open[7]
> >              Open
> > 1995-11-13 949.29
> > > prices$Close[6]
> >             Close
> > 1995-11-10 948.82
> > > if (prices$Open[7]< prices$Open[6]) 1 else 0
> > Error in if (prices$Open[7] < prices$Open[6]) 1 else 0 :
> >   argument is of length zero
> > > str(prices)
> > An ‘xts’ object from 1995-11-03 to 2010-07-02 containing:
> >   Data: num [1:3637, 1:5] 1000 1002 987 976 960 ...
> >  - attr(*, "dimnames")=List of 2
> >   ..$ : NULL
> >   ..$ : chr [1:5] "Open" "High" "Low" "Close" ...
> >   Indexed by objects of class: [POSIXt,POSIXct] TZ:
> >   xts Attributes:
> >  NULL
> >
> >
> > --
> > 'Raghu'
> >
>
>
>
> --
> 'Raghu'
>
>        [[alternative HTML version deleted]]
>
>
> _______________________________________________
> 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]]

