10 minutes is a shockingly short period of time!
Today, some common errors you WILL see when you try to read in data. The code below has many typos.
Watch for Windows to mistakenly save your file as “advertising.csv.txt”. Windows might append that “.txt” without you’re being aware. Open the folder properties in “C:/myR” and unhide the file extensions.
Sometimes missing values in your spreadsheets have hidden characters, or R gets confused about the data type. Remember, R tries to guess whether each column in your data is a number or a factor or categorical variable. To avoid difficulties use the argument: na.strings=”” where “na” means “missing data” inside R.
Notice there is no space between the quotation marks. You can also specify a value that means missing. Perhaps—NEVER DO THIS—you coded missing as “99” or something equally foolish. Then you could use na.strings=”99″. We’ll talk about data coding another time.
Cut and paste or type the following NEW block of text into your myRcode.R file and SAVE it.
# Common errors
x = read.csv("C:\myR\advertising.csv")
x = read.csv("C:/myr/advertising.csv")
x = read.csv("C:/myR/advertisng.csv")
x = read.csv("~/Desktop/myr/advertising.csv")
x = read.csv("Desktop/myR/advertising.csv")
x = read.csv("~/Desktop/myr/advertisng.csv")
x = read.csv("myR/advertising.csv")
x = read.csv("/home/matt/myr/advertising.csv")
x = read.csv("/home/matt/myR/advertisng.csv")
# Good code
x = read.csv("C:/myR/advertising.csv", na.strings="")
x = read.csv("~/Desktop/myr/advertising.csv", na.strings="")
x = read.csv("/home/matt/myR/advertising.csv", na.strings="")
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).
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 firstname.lastname@example.org.