From d44c641c3f45b6b5323eaa80d4453c0ff5493a7f Mon Sep 17 00:00:00 2001 From: Ian Lyttle Date: Sun, 27 Mar 2016 15:26:57 -0500 Subject: [PATCH] just a couple of typos --- iteration.Rmd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iteration.Rmd b/iteration.Rmd index bd7e004..d9b2b78 100644 --- a/iteration.Rmd +++ b/iteration.Rmd @@ -17,7 +17,7 @@ In [functions], we talked about how important it is to reduce duplication in you 1. You're likely to have fewer bugs because each line of code is used in more places. -One part of reducing duplication is writing functions. Functions allow you to identify repeated patterns of code and extract them out into indepdent pieces that you can reuse and easily update as code changes. Iteration helps you when you need to do the same thing to multiple inputs: repeating the same operation on different columns, or on different datasets. (Generally, you won't need to use explicit iteration to deal with different subsets of your data: in most cases the implicit iteration in dplyr will take care of that problem for you.) +One part of reducing duplication is writing functions. Functions allow you to identify repeated patterns of code and extract them out into independent pieces that you can reuse and easily update as code changes. Iteration helps you when you need to do the same thing to multiple inputs: repeating the same operation on different columns, or on different datasets. (Generally, you won't need to use explicit iteration to deal with different subsets of your data: in most cases the implicit iteration in dplyr will take care of that problem for you.) In this chapter you'll learn about two important iteration paradigms: imperative programming and functional programming, and the machinary each provides. On the imperative side you have things like for loops and while loops, which are a great place to start because they make iteration very explicit, so it's obvious what's happening. However, for loops are quite verbose, and include quite a bit of book-keeping code, that is duplicated for every for loop. Functional programming (FP) offers tools to extract out this duplicated code, so each common for loop pattern gets its own function. Once you master the vocabulary of FP, you can solve many common iteration problems with less code, more ease, and fewer errors. @@ -114,7 +114,7 @@ That's all there is to the for loop! Now is a good time to practice creating som 1. Compute the mean of every column in the `mtcars`. 1. Determine the type of each column in `nycflights13::flights`. 1. Compute the number of unique values in each column of `iris`. - 1. Generate 10 random normals for each of $mu = -10$, $0$, $10$, and $100$. + 1. Generate 10 random normals for each of $\mu = -10$, $0$, $10$, and $100$. Think about output, sequence, and body, __before__ you start writing the loop.