There are many ways of reading data into R, and I am only going to discuss a few of them. Most texts or Web pages on R will tell you about other ways. The idea is to go out to your computer or the web and open a file that you can then use.
Suppose that you took my advice and downloaded the zipped data file for the Methods book. In my particular case the unzipped files are saved in a directory (folder) named "C:/Users/Dave/Documents/Webs/methods8/DataFiles". If I want to open the Add.dat file from that folder I can do it is several different ways. The first way lets me specify exactly where the file is. I just enter
theData <- read.table("C:/Users/Dave/Documents/Webs/methods8/DataFiles/Add.dat", header = TRUE )
Remember that the "header = TRUE" is telling R that the first line of that file will contain variable names. Also remember that the slashes have to be the kind I have used here--often called "forward slashes."
An alternative way is to have R ask me to find the file. I can do this by entering
theData <- read.table(file.choose(), header = TRUE )
A dialog box will open and I can navigate my way to the appropriate file.
But hunting around on my computer takes time, and I can make things very much easier if I tell the program where to start looking. In other words, I want to give it a "default directory," and it will start looking there. One way to do this is to go to the R Console and, under file select "change directory." If you want to build that into your program rather than use the console, just enter the following command. Note that there is no "<-" or "=" sign in this command, though a reasonable person might have expected there to be one.
setwd ("C:/Users/Dave/Documents/Webs/methods8/DataFiles")
Having established the working directory, the program will always start looking in that location. So now I can use the next command as an alternative.
theData <- read.table("Add.dat", header = TRUE )
and the file will automatically go to the proper directory and download the appropriate file.
All of the files for the Methods book are available on the Web. Therefore you don't really need to download them if you are always going to have Internet access when playing with R. All that we really have to do is to change the location where we tell R to find the data. This is actually quite simple.
WebData <- read.table("https://www.uvm.edu/~dhowell/methods8/DataFiles/Ex10-1.dat", header = TRUE)
That's pretty easy. My eventual plan is to go back to all of the R programs that I have written for this supplement and put in both kinds of data access. In other words I will use the "html" address and the address of a specific file on my machine. One of those will be preceded by an "#" to comment it out. If you want the specific computer address you will have to modify what I give to point to files on your own machine.
There is one final way that I'll mention, though I have never used it. Some people and programs like to have variables in a data file separated by a comma. This is called "csv" for "comma separated variables." If you want to enter data that way, you can enter the line shown below. Finally, if you happen to have data in an SPSS systems file (not a raw data file), you can download the "foreign" package, install and then load it, and use "?read.spss" to see how to import those files. I have never done this, but you can certainly try. Finally, you can read data from an Excel spreadsheet by first using Excel to save it as a tab-delimited file and then reading it as:
dch:newdata <- read.table(file = "AirQual.txt" , header = TRUE, sep = "\t")