在R中使用多个代码

时间:2018-10-30 00:29:52

标签: r

我正在尝试在R中加载多个代码,并且不断收到错误“ auto.assign = TRUE”,但我不知道将其放置在哪里...下面是我的代码

library(zoo)
library(tseries)
library(fBasics)

quote = "AdjClose"
start = "2013-01-01"
end = "2015-12-31"
compression = "d"
retclass = "zoo"
provider = "yahoo"
origin = "1970-01-01"
ticker = c("aapl", "ebay", "goog","bbby")   

我认为我的价格有误...

Prices = get.hist.quote(instrument = ticker, start = start, 
         end = end, quote = quote, provider = provider,
         origin = origin, compression = compression, 
         retclass = retclass)

我尝试添加一个循环...

for(ticker in c("aapl", "ebay", "goog", "bbby")){
Prices = get.hist.quote(instrument = ticker, start = start,
                        end = end,quote = quote, provider = provider,
                        origin = origin, compression = compression, 
 retclass = retclass)}

但是当我打印出价格时,它只会执行最后一个跟踪器。它用第二和第一与第二,第三和第三与第四分别覆盖了股票代码。我怎样才能打印出每个不同行情的所有价格?

2 个答案:

答案 0 :(得分:0)

仪器必须是“给出要下载的引号的名称的字符串”。尝试遍历您的四个股票。

它仅执行最后一个报价,因为您的循环正在覆盖价格。也许您会找到答案here

答案 1 :(得分:0)

您可以使用列表来存储不同的zoo系列:

Price <- list()
for(ticker in c("aapl", "ebay", "goog", "bbby")){
  Price[[ticker]] <- get.hist.quote(instrument = ticker, start = start,
                          end = end,quote = quote, provider = provider,
                          origin = origin, compression = compression, 
                          retclass = retclass)
}

这将使您可以访问一系列独立的报价器,例如Price$aapl