7) Iterations
๐ Lecture
In addition to writing functions to reduce duplication in your code, you also need to learn about iteration, which helps you when you need to do the same operation several times. Namely, we review control flow structures such as for loops, while loops, repeat loops, and the apply family functions.
๐ Reading
Read chapters 13 and 14 of โR Coding Basicsโ:
๐ฌ Lab
Youโll keep working writing a variety of loops in R (e.g. for, while, repeat).
๐ฏ Objectives
At the end of this week you will be able to:
- Write for loops to repeat the same operation a given number of times
- Write while loops to repeat the same operation an unknown number of times
๐ Shiny Friday
The shiny app for this week is the same one from last week: it uses mtcars
data set to visualize the top-n cars given a selected variable.
An important component of this app is the use of the reactive()
function to create so-called reactive conductors (i.e. an R expression that uses widget input(s) and returns a value).
- mtcars-topn-barchart: produces a simple barchartโvia
"ggplot2"
โto visualize the top-n cars given a selected variable. In addition to the plot, it also displays a table with the top-n cars. More important, this app uses a so-called reactive conductor element.
https://github.com/data133/shiny/tree/main/mtcars-topn-barchart
๐ Assignments
- HW5 due this 03/01
- HW6 released on 03/02, due 03/08