Iterations in R
In this third lesson of our interactive control flow, iteration, and functions course, you'll learn about iterating through elements of your dataset using R code.
This lesson will teach you how to write for loops in R, while loops in R, and even give you a second approach to writing for loops. But perhaps more importantly, it will also cover why we might want to use iterators in the context of data analysis, and when iterators are the wrong choice.
Over the course of the lesson, you'll write for loops and while loops to iterate through a real dataset using real R code, but you'll also learn about the differences between iteration and vectorization, and when you might choose to use one over the other.
After you finish this lesson, you will be comfortable with iterations in R, including for loops and while loops, and you'll have a solid grasp of when and why they should be used (and just as important, when they shouldn't).
- Motivation for Iteration
- The for Loop
- Another Way to Write for Loops
- Intuition Behind the while Loop
- A while Loop Example
- Your Own while Loop
- Iteration vs. Vectorization
- Next Steps