Instructions

Suggested readings

Required R packages

set.seed(123) # this ensures that any psuedo-random computations are always the same

1. Installing and running R

a.

Your first task is simply to show that you have been able to install and run R and R Markdown. You don’t have to change this code, just uncomment it. Then the correct output will automatically appear when you ‘knit’ the document.

# UNCOMMENT THE CODE

#R.version

#sessionInfo()

Which version of R are you running? On which platform are you running it?

ANSWER:

(your answer here)

b.

Install the package tidyverse. Don’t install it in the code below. Instead, install it through the console. Then write code below to load the package and show the sessionInfo again.

# YOUR CODE HERE

Which version of tidyverse do you have installed?

ANSWER:

(your answer here)


2. Tibbles (tidy tables)

The ToothGrowth data set comes with base R. You can read about this data set by running ?ToothGrowth in the console. It is a data frame. In this course, we prefer to use tibbles (tidy tables) instead of data frames.

a.

Convert the ToothGrowth data frame into a tibble using as_tibble(). Put this in a new variable called iris_tibble. Then print the tibble using the print() function.

# YOUR CODE HERE

Which data type is the variable “supp”?

ANSWER:

(your answer here)

b.

Starting from the complete ToothGrowth data set, filter only the guinea pigs that were give orange juice.

# YOUR CODE HERE

How many datapoints (i.e. guinea pigs) are left?

ANSWER:

(your answer here)

c.

Starting from the complete ToothGrowth data set, filter only the guinea pigs that received ascorbic acid and had a dosage of 1.0mg or greater.

# YOUR CODE HERE

d.

Find out the mean length for the two supplement types. Do this with by piping tooth_growth_tibble to group_by() and then to summarise(). For instructions read the help page for summarise().

# YOUR CODE HERE

What is the mean tooth length for guinea pigs that received Orange Juice?

ANSWER:

(your answer here)


3. Plotting data

a.

Using the ToothGrowth data set, create a plot of dose (x axis) against length (y axis) using ggplot(). Show the two supplement types in different colours.

# YOUR CODE HERE

After visually inspecting the graph, does there seem to be any difference between the types of supplement?

ANSWER:

(your answer here)


End of homework sheet