Download Datasets

Follow the steps to download a dataset as an Excel file. Rename the file. For example, if this is the dataset for homework 0202 question 01, you may rename the file as 020201.xlsx.

Convert to .csv File

Open the downloaded file in Excel and save it as .csv file.

Load Datasets into R

Use the following command to load the data.

  • Mac version:

    df <- read.csv("/Users/your-user-name/Downloads/020201.csv", header = FALSE)
  • Windows version:

    df <- read.csv("C:/Users/Your-user-name/Downloads/020201.csv", header = FALSE)

Be sure to

  1. replace your-user-name with the actual user name on your laptop;
  2. replace 020201.csv by the correct file name;
  3. set header = TRUE if the data file has column names. (In the example here, the column doesn’t have a name, so we set header = FALSE.)


Now we can access the data.

  • For dataset that has a single variable, provide a meaningful name to the variable, e.g., salary. Then use df$salary to access the data.

    names(df) <- c("salary")
    df$salary
  • For dataset that has multiple variables, e.g., ‘Tap’ and ‘Bottled’. After successfully loading the data file into R, use df$Tap and df$Bottled to access the two variables, respectively.

    If we would like to change the variable names, e.g., use ‘t’ for tap water and ‘b’ for bottled water, type names(df) <- c("t", "b") and then use df$t and df$b to access each variable.