Week 2: Foundations of R Programming
Main reference
What you will learn this week
- Subsetting
- Control flow
- Functions
- Environments
- Conditions
Pre-class activities
Watch the following series of short videos on subsetting in R:
Write a function
linear, that takes argumentsx,aandb, and returnsa + b * x. Give default valuesa=0andb=1, and make sure your function has sensible error messages when the inputs are not as expected. Your function should work whenxis a numerical scalar, vector, or matrix.
Slides for week
Assignments
- Assignment 1 is due on Tuesday 31 March.