繁体   English   中英

在R中使用quantmod包修复错误时遇到问题:继承错误(x,“xts”):找不到对象“M”

[英]Having trouble fixing error using quantmod package in R : Error in inherits(x, “xts”): object 'M' not found calls

下面是我的代码。 我想要做的是下载股票和情节图表的多个符号,但我收到此错误:

继承错误(x,“xts”):对象'M'未找到调用:... eval-> chartSeries - > try.xts - > is.xts - > inherits

library(quantmod)
stocks <- c("INFY.NS","HINDALCO.NS","TCS.NS","TATASTEEL.NS","NESTLEIND.NS",
  "TECHM.NS","HCLTECH.NS","HDFCBANK.NS","JETAIRWAYS.NS","BLUEDART.NS",
  "AUROPHARMA.NS","APOLLOHOSP.NS", "IOC.NS", "HINDPETRO.NS","BHEL.NS",
  "NTPC.NS", "HINDZINC.NS", "M&M.NS", "RELIANCE.NS","ONGC.NS", "ORIENTBANK.NS",
  "MARUTI.NS", "ASHOKLEY.NS", "ASIANPAINT.NS", "DABUR.NS", "DRREDDY.NS",
  "BHARTIARTL.NS", "BATAINDIA.NS", "LTI.NS")
getSymbols(stocks,from="2017-01-01")
chartSeries(INFY.NS)  
chartSeries(HINDALCO.NS)
chartSeries(TCS.NS)
chartSeries(TATASTEEL.NS)
chartSeries(NESTLEIND.NS)
chartSeries(TECHM.NS)
chartSeries(HCLTECH.NS)
chartSeries(HDFCBANK.NS)
chartSeries(JETAIRWAYS.NS)
chartSeries(BLUEDART.NS)
chartSeries(AUROPHARMA.NS)
chartSeries(APOLLOHOSP.NS)
chartSeries(IOC.NS) 
chartSeries(HINDPETRO.NS) 
chartSeries(BHEL.NS) 
chartSeries(NTPC.NS)
chartSeries(HINDZINC.NS)
chartSeries(M&M.NS)
chartSeries(RELIANCE.NS)
chartSeries(ONGC.NS)
chartSeries(ORIENTBANK.NS)
chartSeries(MARUTI.NS)
chartSeries(ASHOKLEY.NS)
chartSeries(ASIANPAINT.NS)
chartSeries(DABUR.NS)
chartSeries(DRREDDY.NS)
chartSeries(BHARTIARTL.NS)
chartSeries(BATAINDIA.NS)
chartSeries(LTI.NS)

问题是M&M.NS不是语法上有效的R名称( &具有特殊含义)。

library(quantmod)
getSymbols("M&M.NS")
chartSeries(M&M.NS)    # error
chartSeries(`M&M.NS`)  # use backticks for names that aren't syntactically valid

或者,您可以使用setSymbolLookup()将符号映射到语法上有效的名称。 然后,您可以在getSymbols()chartSeries()调用中使用语法上有效的自动getSymbols() chartSeries()

setSymbolLookup(M.AMP.M.NS = list(name = "M&M.NS"))
getSymbols("M.AMP.M.NS")
chartSeries(M.AMP.M.NS)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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