Practical 4

Author
Affiliation

Alexia Cardona

Department of Genetics, University of Cambridge

Further data visualisation and manipulation with tidyverse

Aim

The aim of this practical is to build on practical 3 and explore further how we can automate our code in R.

Objectives

During this practical you will learn:

  • creating user-defined functions
  • if else statement
  • for loops
  • explore further R concepts independently

Instructions

The best way to do this practical is to read the Practical Notes which will introduce the concepts of this practical. These notes are designed with all the details you would need to be able to perform the exercises in this practical. In general, you would not need to refer to additional texts and resources as these notes have been explained in detail. Apart from the exercises listed below, there are also examples throughout the notes which provide insight on the concepts introduced, and therefore, it is recommended that you also run these examples as you progress through the practical notes.

If you are an experienced R programmer, you might find that you already know about the content in these notes. You may want to skip sections of notes that you already know and attempt the exercises that are at the higher levels.

Exercises levels

Exercises in this practical are labelled with the level of difficulty of the respective exercise:

Level Description
Level 1: Exercises in Level 1 are simple exercises designed to get you familiar with the R syntax. If you already know how to program in R, you may skip these exercises.
Level 2: Exercises in Level 2 combine different R programming concepts to solve simple problems.
Level 3: Exercises in Level 3 solve more complex problems.

Exercises

This practical is composed of the following exercises:

Exercise Description Level
Exercise 16 creating functions: In this exercise we will practice creating user-defined functions.
Exercise 17 if else: The exercise uses if else statements.
Exercise 18 for loop: In this exercise we practice the for loop.
Exercise 19 nested for loops: The exercise uses nested for loops.
Managed to solve all the exercises? Well done! You’ve earned all your R badges!


In the programming world, many organisations award badges to learners on the acquisition of a new skill or completion of a milestone. If you attempted and solved all the exercises of this practical, you definitely deserve your second R badge of this course.