Exercises for 1.3: Some important practical matters

Exercise 1.3.1: Loading a package

  • Use the check boxes in the Rstudio packages tab to load the nlme package
  • Uncheck the box to unload (“detach”) the nlme package

Exercise 1.3.2: Installing packages

There’s a few packages we’ll need for the rest of the workshop. So, for this exercise, use the “install packages” button in the Rstudio package tab to install the following packages:

  • lsr : Companion to “Learning Statistics with R”, written by Dan Navarro
  • psych : Psychometrics and Personality functions, written by William Revelle
  • car : “Companion to Applied Regression”, written by John Fox

It’s worth installing the ez package too: we won’t use it for the exercises, but it’s a good package for repeated measures ANOVA, and I do talk about it later on.

Exercise 1.3.3: Loading an .Rdata file

The data set that we’ll use for the exercise is located online at

http://ua.edu.au/ccs/docs/lsr/driving.Rdata

Open a browser, go to that address and save the file to disk. In my case, I saved it to

~/Work/Research/Rbook/workshop_dsto/datasets/driving.Rdata

where ~ is a standard symbol used in Unix-like operating systems such as Mac OS X that refers to “the current user’s home directory”, which for my current machine would be /Users/dan. I mention this because you’ll sometimes see R refer to the ~ directory, and you might want to know what it means.

In any case, once you’ve saved the file to disk somewhere, use the load button in the Rstudio workspace tab to open it. You’ll see that there’s only one variable there, a data frame called driving.

Exercise 1.3.4: Saving the current workspace to a file

Create a few new variables, and then use the save button in the Rstudio workspace tab to save it to disk. Don’t overwrite the existing driving.Rdata file: call it something like driving_version2.Rdata or something. I generally find that it’s a good idea to leave the original data file in pristine condition.

Exercise 1.3.5: Importing a CSV file

There is a CSV version of the driving data frame located at

http://ua.edu.au/ccs/docs/lsr/driving.csv

Save it to disk, and import the data using the “import dataset” menu in the Rstudio workspace tab.

Exercise 1.3.6: Writing a script

  • use the Rstudio toolbars to open a new script
  • use the save button to save it to disk (call it something like newscript.R)
  • write some comments at the top of the script indicating what the script is for (e.g., “this is for a class exercise”), who wrote it (you), and when it was last modified (today). This is a good habit to get into.
  • then add some R commands. Any old commands will do.
  • save it again.
  • click on the “source” button to run the script.