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.
Open the downloaded file in Excel and save it as .csv file.
Use the following command to load the data.
Mac version:
Windows version:
Be sure to
your-user-name with the actual user name on
your laptop;020201.csv by the correct file name;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.
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.