2.2 Loading an R dataset

To load a dataset already in R’s format (.RData), use load(). If it is located in your working directory (which, if you opened R using a Project, is the folder where you created the Project), then you only need the name of the file, not the full path. If it is located in a subfolder of your R Project directory, then specify that subfolder.

DO: Load the Arthritis Treatment dataset (see Section 1.20.1 for more information about this dataset).

# Loading an R data file from your Project directory
# load("RheumArth.RData")

# Loading an R data file from a subfolder in your Project directory
load("Data/RheumArth.RData")

NOTE: The dataset name might not be the same as the file name! Look in the R Studio Environment window or use ls() to see the name of the file you loaded. Then, optionally, use View() to see the contents.

# Check the name of the file you just loaded
ls()
##  [1] "Daily.Cigarettes" "daily_cigarettes" "DailyCigarettes"  "i"               
##  [5] "OR"               "RheumArth"        "x"                "X"               
##  [9] "y"                "Y"                "z"
# View the file
View(RheumArth)

A new tab will appear with the dataset in a spreadsheet view: