简体   繁体   English

.xts索引长度中的错误必须与观察数匹配

[英]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.

相关问题 Xts转换错误(与对象长度不匹配) - Xts conversion error (do not match the length of object) lmer错误:分组因子必须是&lt;观察次数 - lmer error: grouping factor must be < number of observations 错误:逻辑索引向量的长度必须为1或10(行数),而不是47428 - Error: Length of logical index vector must be 1 or 10 (the number of rows), not 47428 单个xts元素中出现错误“要替换的项目数不是替换长度的倍数” - Error “number of items to replace is not a multiple of replacement length” in single xts element lmer:“错误:每个分组因子的级别数必须&lt;观察次数” - lmer: "Error: number of levels of each grouping factor must be < number of observations" 错误:逻辑索引向量的长度必须为 1 - Error: Length of logical index vector must be 1 如何通过取先前的值来增加 xts 对象中的观察次数? - How to increase the number of observations in xts object by taking previous value? R - xts 对象中每月的观察次数(工作日数据) - R - Number of observations per month in an xts object (weekday data) 运行混合效应模型时出错 -- 错误:每个分组因子的水平数必须小于观察数 - Error when running mixed effects model -- Error: number of levels of each grouping factor must be < number of observations R xts NextMethod替换长度错误 - R xts NextMethod replacement length error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM