Importing Data into R

From a comma separated file:

DataD1 ← read.csv(file="table.csv",header=TRUE, ...)

help(read.cvs) for all the options which include reading row names

read.table(file="table.csv", sep=", " …)

help(read.table) for all the options


library(gdata)

(load the package gdata)

read.xls("table.xls", sheet=4, …)

help(read.xls) for all the options

In each case above the file is put into a “data frame” which can be referenced by row and column.


Transcript

Now to import the data into R, what we do is we basically say: Well, a common format of is comma-separated variables sorry comma-separated values .csv and there's an operator called read.csv were we specify the file and we say whether or not there's a header for each of the columns in the table. If there is, we set header to TRUE, and we assign the result to the table that's going to store the data that we want.  Now once we have it, we can manipulate it using all the various R tools. In addition, we can say, "Well, actually I've already got it in the spreadsheet so if I have it in an Excel spreadsheet I can still load the package gdata and now you can call read.xls and even say which particular sheet of the spreadsheet I want to read and now will get loaded into a data frame which now I can reference by rows and columns."