[R-SIG-Finance] Why this R code dont work ?

Josh Ulrich josh.m.ulrich at gmail.com
Mon Jul 14 22:59:12 CEST 2008


Ops.xts (like Ops.zoo) requires both observations to have the same
index value.  You want to compare observations with different index
values... so you should use:

coredata(xCl[1]) < coredata(xCl[2])

Best,
Josh
--
http://quantemplation.blogspot.com


On Mon, Jul 14, 2008 at 3:38 PM, Pierre8r <pierre8r-gmane at yahoo.fr> wrote:
> Hello,
>
>
> Why this R code dont work ?
>
> Error in French :
> Erreur dans if (xCl[1] < xCl[2]) { : l'argument est de longueur nulle
>
> Thanks,
>
> Pierre8r
>
> library(quantmod) # this also pulls in zoo
> library(xts) # this also pulls in zoo
>
> Lines <-
> "2007-12-03  100.00  110.00  90.00  110.00  10.0
> 2007-12-04  110.00  120.00 100.00  120.00 10.0
> 2007-12-05  120.00  130.00 110.00  130.00 10.0
> 2007-12-06  130.00  140.00 120.00  140.00 10.0
> 2007-12-07  140.00  140.00 120.00  140.00 10.0
> 2007-12-08  130.00  130.00 110.00  120.00 10.0
> 2007-12-09  120.00  120.00 120.00  140.00 10.0
> 2007-12-10  110.00  130.00 120.00  140.00 10.0
> 2007-12-11  100.00  120.00 120.00  140.00 10.0 "
>
>
> x <- read.zoo(textConnection(Lines))
>
> x <- as.xts(x)
>
> colnames(x) <- c('Open','High','Low','Close','Volume')
>
> xCl  <- Cl(x)
>
> if (xCl[1] < xCl[2] ) {
>  print("xCl[1] < xCl[2] OK")
> } else
> {
>  print("xCl[1] < xCl[2] KO")
> }
>
> _______________________________________________
> 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.
>



More information about the R-SIG-Finance mailing list