# Load a CSV File With R

## Prerequisites

• No additional R packages are necessary for this notebook to run
• Cells in this notebook expect the Car Sales.csv file to be in certain locations; specifics are in the cell itself

## Load Data From a CSV File

### File is in the same directory as your Jupyter Notebook

# Read the CSV file

# Show the first 5 rows
head(car.sales, 5)
Clyde's Clunkers902 650 754 792 1 2018
Clyde's Clunkers710 476 518 492 2 2018
Clyde's Clunkers248 912 606 350 3 2018
Clyde's Clunkers782 912 858 446 4 2018
Clyde's Clunkers278 354 482 752 5 2018

### File is in a different directory than your Jupyter Notebook

The example will use your “home directory” to make this example applicable across operating systems, but you can use any path as long as the file exists there…

# Make sure to use "\" slashes and not "/" slashes (it's a Windows thing)
# There actually needs to be folders named "Path" and "To" and "CSV" and "File"
# in your home directory (the "~" means "home directory") for this cell to work
csv.file.path = normalizePath("~\\Path\\To\\CSV\\File\\Car Sales.csv", winslash = "\\")

# Show the first 5 rows
head(other.path.car.sales, 5)
Clyde's Clunkers902 650 754 792 1 2018
Clyde's Clunkers710 476 518 492 2 2018
Clyde's Clunkers248 912 606 350 3 2018
Clyde's Clunkers782 912 858 446 4 2018
Clyde's Clunkers278 354 482 752 5 2018

### From a URL

# Note the URL Encoding with "%20" for spaces

# Show the first 5 rows
head(url.car.sales, 5)
Error in read.table(file = file, header = header, sep = sep, quote = quote, : object 'url_to_csv_file' not found
Traceback: