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

Gabor Grothendieck ggrothendieck at gmail.com
Mon Jul 14 23:02:17 CEST 2008


xCl[1] and xCl[2] are xts/zoo time series and when you try to compare
them they get merged and aligned implicitly and then values at
the same times in each are compared.  In this case they are time
series of length 1 that occur at different times so the intersection
of their times is empty.  Try:

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

On Mon, Jul 14, 2008 at 4: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