From 8b9315fe55b30089c5cf0e0bc5867cfa489f57ab Mon Sep 17 00:00:00 2001 From: Emma Rand Date: Mon, 18 Sep 2023 05:35:52 -0500 Subject: [PATCH 1/2] summary added --- 03-iteration-01.qmd | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/03-iteration-01.qmd b/03-iteration-01.qmd index 483bf9a..4f61afb 100644 --- a/03-iteration-01.qmd +++ b/03-iteration-01.qmd @@ -17,13 +17,13 @@ bibliography: references.bib ## Overview -brief intro +In this session we will cover another way to reduce code duplication: iteration. ## Learning Objectives At the end of this section you will be able to: -::: {style="font-size: 70%;"} +::: {style="font-size: 80%;"} - recognise that much iteration comes free with R - iterate across rows using `across()` @@ -303,6 +303,8 @@ penguins |> We get the NA because we have missing values[^1]. +[^1]: There is no problem when we use `sd_error()` because we accounted for NA in our function definition + ## Include arguments `mean()` has an `na.rm` argument. @@ -582,12 +584,13 @@ penguins |> ## Summary -- - -- +- you already knew some iteration: `group_by()`, `facet_wrap()` -- +- `across()` iterates over columns` + - choose coulmns with familiar `select()` spec + - pass functions without their `()` + - use anonymous functions to add arguments + - use a list to use multiple functions + - specify the names +- You can use `across()` in functions! -- - -[^1]: There is no problem when we use `sd_error()` because we accounted for NA in our function definition From 1bc1dfa08d26d451b7931b18a75f1f9f14742b5c Mon Sep 17 00:00:00 2001 From: Emma Rand Date: Mon, 18 Sep 2023 06:59:04 -0500 Subject: [PATCH 2/2] minor reorder --- 03-iteration-01.qmd | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/03-iteration-01.qmd b/03-iteration-01.qmd index 4f61afb..6157563 100644 --- a/03-iteration-01.qmd +++ b/03-iteration-01.qmd @@ -84,7 +84,6 @@ and NOT We have: -- the `apply()` family - `group_by()` with `summarize()` @@ -92,6 +91,9 @@ We have: - `across()` and `purrr()` +. . . +- the `apply()` family + . . . other languages, a for loop would be right after hello world