Unit 2
Introduction
Welcome to Week 2 of BIO144!
Learning objectives for the week
These learning objectives, together with the content of the course book chapter, define what you need to know for the exam.
After this unit, students will be able to:
- Explain the purpose of the script, the console and the environment in RStudio.
- Write and run R code in a script, using objects, functions and arguments correctly.
- Install and load add-on packages, and explain the difference between installing and loading a package.
- Use R’s help system and other resources to find out how a function works and what arguments it takes.
- Import a dataset into R and inspect its structure, including the variable names and variable types.
- Convert variables to factors, and set or change the reference level of a categorical variable.
- Manipulate data in R: select variables, filter observations, create new variables, and calculate summaries by group.
- Produce exploratory graphs (e.g. histograms, scatterplots, box plots) to inspect distributions of and relationships between variables.
- Identify and fix common errors in R code (e.g. typos, misspelled variable names, packages not loaded).
- Organise an analysis as a script within an RStudio project, with meaningful names for datasets and model objects, that reproduces all results when run from top to bottom.
Book chapter
This week we will be covering Chapter 2: R and RStudio of the course book.
Video and code walkthrough
Each chapter of the course book has a code walkthrough: an R script with the code of the chapter, with comments explaining each step, and a video in which Owen works through the script. Use them to learn the R code you need this week. Work through them before the practical, ideally running the script line by line while you watch the video. The last section of the script (“Practical toolbox”) shows code that the practical uses but the chapter does not.
Script: walkthrough_ch02_r_and_rstudio.R
To download the script straight into your RStudio project folder (for example on RStudio Server), run this line in the Console:
download.file("https://opetchey.github.io/BIO144_Course_Book/walkthroughs/walkthrough_ch02_r_and_rstudio.R", destfile = "walkthrough_ch02_r_and_rstudio.R")
Video: coming soon.
Lecture
Please attend the lecture. If for any reason you can’t, please watch the podcast, which is available on OLAT.
Optional: some ideas for how you could prepare for the lecture (no preparation is also fine) are in Preparing for lectures.
Homework, Practical, and Weekly Quiz
Available here. You will need to be on a UZH network to access this link, so if you are not on campus, you will need to connect to the UZH VPN first.