简体   繁体   中英

Error in .xts index length must match number of observations

When dealing with timeseries data what does this error mean? Does it have something to do with some columns having NA ? This SO post solves the issue for someone else, but I specifically would like someone to explain how the length could be wrong , and whether or not the second error is caused by the first .

> add.signal(strat, name="sigFormula", arguments=list(columns=c("ADX.adx","rsi"), 
+     formula="ADX.adx>25 && rsi<50"), label="enterLONG")
[1] "tempEnv"
> test <- applySignals(strat, mktdata=test)

Error in .xts(eval(parse(text = formula), as.list(data)), index = .index(data)) : 
  index length must match number of observations
Error in `colnames<-`(`*tmp*`, value = seq(ncol(tmp_val))) : 
  attempt to set 'colnames' on an object with less than two dimensions

> View(test)
> colnames(test)
 [1] "Open"                 "High"                 "Low"                  "Close"               
 [5] "Volume"               "rsi"                  "tr.ATR.ind"           "atr.ATR.ind"         
 [9] "trueHigh.ATR.ind"     "trueLow.ATR.ind"      "dn.bbInd"             "mavg.bbInd"          
[13] "up.bbInd"             "pctB.bbInd"           "DIp.adx"              "DIn.adx"             
[17] "DX.adx"               "ADX.adx"              "SMI.stoch.fastind"    "signal.stoch.fastind"

The solution was to change && to & ie: formula="ADX.adx>25 & rsi<50" . Thanks to @Joshua Ulrich I discovered the reason:

& and && indicate logical AND. The shorter form performs elementwise comparisons in much the same way as arithmetic operators. The longer form evaluates left to right examining only the first element of each vector.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM