How to Import Data via Web Scraping RStudio
Updated: Oct 1
RStudio is an integrated development environment for R, a programming language for statistical computing and graphics.
In this blog, we go over importing data from the internet into RStudio.
Steps to in RStudio
Find the data that you would like to import and copy the URL link to that page (we're using https://www.iseecars.com/cars-that-hold-their-value-study#v=2019)
In RStudio, make sure to have the required packages: tidyverse, readxl, and rvest
Once you have those packages, you can Run the libraries and make sure they are loaded in
Create a variable, can be named whatever you like (we named it cars)
cars gets assigned to the read_html function with the URL link of the page you want to import the data from, refer to the following:
cars <- read_html("https://www.iseecars.com/cars-that-hold-their-value-study#v=2019")
Run that line and you should see the cars variable pop up in the Environment window on the right
Create another variable (we named it tables)
tables get assigned to cars and piped into html_table function (from rvest) and fill = true and Run that
tables <- cars %>%html_table(fill = TRUE)
Now, there should be a tables variable in the Environment
Last step, create a third variable specifying which table we want to grab since there's multiple tables on the page (we called it table10 since it happened to be the 10th one on that page)
table10 gets assigned to tables function with brackets including the number 10
table10 <- tables[]
Once you have that, you can Run it and you should see the variable table10 show up in the Environment
Open up table10 variable and you will see all the data imported from the web
For a more step by step visual tutorial, here's the video.
Check out this blog where you can rename columns in Tibble RStudio.
#rstudio #tibble #r #coding #program #language #statistical #computing #howto #import #data #internet #packages #link #web #scraping #rename #columns #table #variables #data #qbo #excel #bookkeeping #financialservices #accounting #financialgps