0

I'm downloading stock data with 5 symbols in stock_list. The following code works:

stock_list <- c("ZM", "XLNX", "XEL", "WDC", "WDAY")

master_df <- NULL
for (idx in seq(length(stock_list))){
  stock_index = stock_list[idx]
  getSymbols(stock_index, verbose = TRUE, src = "yahoo") 
  temp_df = as.data.frame(get(stock_index))
  temp_df$Date = row.names(temp_df)
  temp_df$Index = stock_index
  row.names(temp_df) = NULL
  colnames(temp_df) = c("Open", "High", "Low", "Close", 
                        "Volume", "Adjusted", "Date", "Index")
  temp_df = temp_df[c("Date", "Index", "Open", "High", 
                      "Low", "Close", "Volume", "Adjusted")]
  master_df = rbind(master_df, temp_df)
}

The stock symbols are also in "data" from excel; 1 column, 5obs. Details show the following: Factor with 5 levels.

How can I transform the data and write for example stock list <- c(xy), so that I don't have to write the symbols manually into the list?

So I tried: stock_list <- c(data)

Console shows:

*$ï..Nasdaq5Symbole
[1] ZM   XLNX XEL  WDC  WDAY

Levels: WDAY WDC XEL XLNX ZM*

And how can I solve the length problem (see error below) ??

*Error in attributes(.Data) <- c(attributes(.Data), attrib) : 
  'names' attribute [5] must be the same length as the vector [1]*
Sinval
  • 1,315
  • 1
  • 16
  • 25
posti
  • 1
  • 1

0 Answers0