Web Scraping of SPY Stocks
Hey there, The error message has it right, there is no column "Ticker Symbol" in that table. When you look at the wikipedia page, the column's name is simply "Symbol". For general debugging when using magrittr pipes I find it useful to copy/paste each expression, adding one additional pipe at a time to see at which stage the error message. Also, please make sure to include all of the libraries you were using- in this case, appears to be rvest, magrittr, and stringr. With regards to that function, agreed with Joshua- if the above doesn't resolve all your issues, please re-post without html formatting as it's tough to see what's going on. Hope that helps! -Ezra -- ezra at landtucker.com m:?818-203-0269 LinkedIn:?linkedin.com/in/ezztucker Github:?github.com/minimenchmuncher ??????? Original Message ???????
On Saturday, September 26, 2020 8:34 AM, Joshua Ulrich <josh.m.ulrich at gmail.com> wrote:
Please repost your message in plain text (as the posting guide requests). As you can see below, your HTML message was mangled when the list server converted it to plain text. On Fri, Sep 25, 2020 at 3:12 PM AIE ATUMA via R-SIG-Finance r-sig-finance at r-project.org wrote:
Dear All,
Please I need help. I ran the below function and got the highlighted error message. How can I correct it?
library(rvest)# Web-scrape SP500 stock listsp_500 <- read_html("https://en.wikipedia.org/wiki/List_of_S%26P_500_companies") %>%html_node("table.wikitable") %>%html_table() %>%select(`Ticker symbol`, Security, `GICS Sector`, `GICS Sub Industry`) %>%as_tibble()# Format namesnames(sp_500) <- sp_500 %>%names() %>%str_to_lower() %>%make.names()# Show resultssp_500
Error Message:
Error: Can't subset columns that don't exist.x Column `Ticker symbol` doesn't exist.Run `rlang::last_error()` to see where the error occurred.
The second function and the error is below:
get_stock_prices <- function(ticker), return_format = "tibble", ...) { # Get stock prices stock_prices_xts <- getSymbols(Symbols = ticker, auto.assign = FALSE, ...) # Rename names(stock_prices_xts) <- c("Open", "High", "Low", "Close", "Volume", "Adjusted") # Return in xts format if tibble is not specified if (return_format == "tibble") { stock_prices <- stock_prices_xts %>% as_tibble() %>% rownames_to_column(var = "Date") %>% mutate(Date = mdy(Date)) } else { stock_prices <- stock_prices_xts } stock_prices}
"MA" %>% get_stock_prices(return_format = 'tibble')%>%head()
ERROR MESSAGE:
Warning message:All formats failed to parse. No formats found.
Thank You and Best Regards, Emeka I. AtumaIntegrity - Walk Your Talk Don't Talk Your Work
[[alternative HTML version deleted]]
R-SIG-Finance at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
-- Joshua Ulrich | about.me/joshuaulrich FOSS Trading | www.fosstrading.com R-SIG-Finance at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.