Exercises

These exercises will introduce you to using R. There are nine of them. The first six cover the material in the first four Chapters of the Introduction to R book, Exercise 8 is on analysing data in R, and Exercises 7 and 9 cover Chapters 8 and 9 of the book, on writing reproducible reports and on keeping your work under version control. We will be covering these exercises during the first two weeks of the course. It’s entirely up to you how you progress through these exercises, everyone learns R at their own pace and in their own way. You can either work your way through each section of the book and then test your understanding of the material by completing the associated exercise. Alternatively, you can start with each exercise and refer back to the appropriate material in the book. Or find another way that works for you. Whichever approach you use, make sure that you write your R code in RStudio (or your favourite script editor), annotate it liberally and save it regularly. At the end of the course you will have many hundreds of lines of code that you can refer back to at a later date when you’ve forgotten most of it! There is also an additional optional exercise covering Chapter 7 of the book, Programming in R. This exercise is entirely optional and should only be completed after you have finished the nine exercises above.

The solutions and code for each of the exercises are available by following the Exercise Solutions link in the navbar above. If you prefer to download the exercises in pdf format you can find them here.

Finally, just a word about the content of some of the early R exercises. Initially, some of the material in these exercises might strike you as ‘pointless’, ‘trivial’ or ‘irrelevant’ and you may even ask yourself what possible use is generating sequences of numbers, concatenating elements in a vector or ordering lists of names (to name but a few). However, please stick with it, you’ll be amazed how many times you will use the skills (and code) that you have learned throughout these exercises when it comes to dealing with and analysing your own data.

Have fun!

 

Exercise 7 needs R markdown and a LaTeX installation so that you can make PDF documents. Please work through Setting up R markdown before that session.

Exercise 9 needs Git installed and a GitHub account. Please work through Setting up Git and GitHub before that session.

 

pdf version of exercises