[英]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
? 它与某些具有
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 . 这样的SO帖子为其他人解决了这个问题,但是我特别希望有人解释长度可能是错误的 ,以及第二个错误是否由第一个错误引起 。
> 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"
. 解决方案是将
&&
更改为&
即: formula="ADX.adx>25 & rsi<50"
。 Thanks to @Joshua Ulrich I discovered the reason: 感谢@Joshua Ulrich,我发现了原因:
& 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.
较长的形式从左到右求值,仅检查每个向量的第一个元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.