Here I am, a total beginner in R. I am trying to learn more about rvest and how to scrape from the web. Here is the wiki page (https://en.wikipedia.org/wiki/Andy_Murray) and below is the table I want to transfer to R.
Using CSS Selector, I found that the particular table is on ".wikitable". Following some tutorials on other webpages, here is the code that I used:
tennis <- read_html("https://en.wikipedia.org/wiki/Andy_Murray")
trial <- tennis %>% html_nodes(".wikitable") %>% html_table(fill = T)
You were almost there. What you extracted was a list. To get to your desired element you need to use indexing:
To clean it further use:
df <- trial[] df <- df[-1,] df[,17:20] <- NULL
%>% is called pipe from the magrittr/dplyr package. More info here.