Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
316 views
in Technique[技术] by (71.8m points)

transformation - R data into column stock symbols

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]*
question from:https://stackoverflow.com/questions/65928039/r-data-into-column-stock-symbols

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...