4 Further Exercises

Exercise 1

Table 4.1 below shows the annual mean temperature (in degrees Celsius) at 4 different locations along the River Dee for each year from 2015 to 2021. These data have been collected under the Scotland River Temperature Monitoring Network (SRTMN) project.

Table 4.1: Recorded annual mean temperatures across the River Dee in the years 2015 to 2021.
2015 2016 2017 2018 2019 2020 2021
Site 1 NA 6.83 7.01 7.03 6.88 7.06 7.28
Site 2 5.79 6.00 6.25 6.23 6.13 6.25 6.48
Site 3 5.77 6.28 6.53 6.81 6.36 6.55 6.59
Site 4 6.14 6.65 6.83 7.07 6.58 6.86 6.92

Save these data in a matrix called temps and make sure to rename the rows and columns of this matrix so they match the row and column names shown in Table 4.1.

Calculate the mean of all the temperatures from Site 3 across all seven years.

Calculate the mean of the temperatures across all four sites in 2015.

Exercise 2

Make sure the package PASWR2 is installed and loaded in your current RStudio session. From this package, save the data frame SWIMTIMES into your Environment tab. This data set gives the improvement time (in seconds) for 28 swimmers who were randomly assigned to one of two different diets (see more by running the code help("SWIMTIMES")).

Explore the structure of the variables of this data set and change the labels for the levels of the factor diet to be high and low.

What is the mean improvement time for swimmers who were on a high fat diet?

Exercise 3

Mercedes has decided to keep track of different aspects of their life. Below are their notes recording their daily steps, some of their expenses and their most recent exam results.

Create three separate data frames, one for each of these notes, that stores the information shown above. Call them steps, expenses and grades respectively.

Then, combine these data frames into a single list so that Mercedes can easily continue to track these parts of their life.

Can you write code to show only the expenses from 14/08, using the list you have created?