R Lecture 6: Reading External Data Part I

10 minutes is a shockingly short period of time!

Go to https://www.wmbriggs.com/book/ and save the advertising.csv file into your myR folder.

Make SURE it is saved as a CSV file and NOT a CSV.TXT file: sometimes Windows thinks it knows more than you.

CSV stands for comma separated value: these are just text files with rows of data with each column separated by a comma. They can be read into any spreadsheet software. If you do not have a spreadsheet, download and use OpenOffice: it’s free and open source.

The read.csv() function reads in a CSV file and places the values from that file into an object. You have to give this object a name. I frequently use “x” because it is short and easy to type. But you can call it anything you like.

The “x” object is called a data frame inside R. In other words, it’s a data set. Why didn’t the R programmers use the name “data.set” instead of “data.frame”? The minds of computer geeks are dark and mysterious.

If you did not put the myR folder where I told you, or if you failed to save the advertising.csv file in that folder, you WILL have problems.

Next time, I’ll show you some of the common problems.

Cut and paste or type the following NEW block of text into your myRcode.R file and SAVE it.

# Data found at:
# https://www.wmbriggs.com/book/advertising.csv
# Windows
x = read.csv("C:/myR/advertising.csv")
# Mac
x = read.csv("~/Desktop/myR/advertising.csv")
# Linux
x = read.csv("/home/matt/myR/advertising.csv")

We will cut & paste this code from the file myRcode.R into the R command window. EACH TIME REMEMBERING TO HIT THE ENTER KEY (inside R).

R can be downloaded here: R-project.org. A direct link to the CRAN package archive is here.

All videos are on YouTube under the username “mattstat” (wmbriggs was taken). That service imposes a ten-minute limit of videos. Accordingly, lectures are short.

All questions to matt@wmbriggs.com.


No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *