getSymbols when tickers list is a dataframe

4119 views r

Sorry for asking what it seems a simple question, but maybe someone can help me.

I'm trying to use getSymbols with my own ticker list.

I have the ticker list imported previously from a .csv file with 55 tickers and seems correctly imported into my environment. But, how can I read the Tickers dataframe correctly when running the getSymbols? Currently I'm having a NULL error when I run the code below.

Tickers <- read.csv("nasdaq_tickers_list.csv", stringsAsFactors = FALSE)
getSymbols(Tickers,from="2018-01-01", src="yahoo" )

If I run class(Tickers) it is a data.frame.

What I'm doing wrong?

Any comment will be appreciated.

Thank you very much.

answered question

1 Answer


If you read the helpfile for getSymbols by doing ?getSymbols, you'll see that the first argument needs to be "a character vector specifying the names of each symbol to be loaded". So do this:

getSymbols(Tickers$VARNAME, ...)

where VARNAME is the column name of the ticker column in your dataframe. Using the $ to subset the dataframe will return the column (a character vector, presumably) rather than the whole dataframe, and will then be what getSymbols expects.

posted this

Have an answer?


Please login first before posting an answer.