I would like to use the yahoofinancer (https://cran.r-project.org/web/packages/yahoofinancer/index.html) package in RStudio to download data from Yahoo's API.
To do so, I need to set a Ticker first. Ticker itself is a class. I would like to use a vector of company symbols to set many Tickers. Something like
stocks<-c("IBM", "AAPL")
aapl <- Ticker$new('aapl')
IBM <- Ticker$new('ibm')
But for more symbols.
To get this, I tried to process the stocks vector in a loop.
library(yahoofinancer)
x <- c()
for (i in stocks){
x[i]<-Ticker$new(i)
assign(i, x[i])
}
This returned the following error:
> Error in x[i] <- Ticker$new(i) : invalid type/length (environment/0) in vector allocation
How can I resolve this error?
I would like to get something like: