In this unit, you will learn how to create functions and learn some programming tricks.
Follow the links to each lecture, lab, and reading.
Scroll down to download the SWIRL lessons.
Lecture: Writing your own functions
Learning Goals:
SWIRL: Writing functions
Lab: Unit 6: Lab 1
Reading: Best practice for writing R code
Functions: function()
Lecture: Control Structures slides
Learning Goals:
SWIRL: Loops
Lab: Unit 6: Lab 2
Reading: Crawley, M. The R Book Ch 2. Essentials of the R Language. 2.10 Loops and repeats
Functions: if()
, else()
, for() {}
, while() {}
, repeat {}
, break
, next
Lecture: Sampling.
Learning Goals:
SWIRL: Sampling and simulation
Lab: Unit 6: Lab 3
Reading: Crawley, M. The R Book Ch 2. Essentials of the R Language. 2.9 Random numbers, shuffling, and sampling
Functions: sample()
, rbinom()
, rnorm()
,