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

Pierre8r pierre8r-gmane at yahoo.fr
Mon Jul 14 22:38:31 CEST 2008


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")
}



More information about the R-SIG-Finance mailing list