In the simplest case, the data you need is already on the internet in a tabular format. There are a couple of strategies here:
- Use
read.csv or read.table to read the data straight into R.
url <- "https://stats.idre.ucla.edu/wp-content/uploads/2016/02/test-1.csv"
df <- read.csv(file=url, header=TRUE, stringsAsFactors=FALSE)
head(df)
## make model mpg weight price
## 1 amc concord 22 2930 4099
## 2 amc oacer 17 3350 4749
## 3 amc spirit 22 2640 3799
## 4 buick century 20 3250 4816
## 5 buick electra 15 4080 7827
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.6 v dplyr 1.0.8
## v tidyr 1.2.0 v stringr 1.4.0
## v readr 2.1.2 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
df <- read_csv(file=url)
## Rows: 5 Columns: 5
## -- Column specification --------------------------------------------------------
## Delimiter: ","
## chr (2): make, model
## dbl (3): mpg, weight, price
##
## i Use `spec()` to retrieve the full column specification for this data.
## i Specify the column types or set `show_col_types = FALSE` to quiet this message.
df
## # A tibble: 5 x 5
## make model mpg weight price
## <chr> <chr> <dbl> <dbl> <dbl>
## 1 amc concord 22 2930 4099
## 2 amc oacer 17 3350 4749
## 3 amc spirit 22 2640 3799
## 4 buick century 20 3250 4816
## 5 buick electra 15 4080 7827