Skip to content

Commit

Permalink
Merge pull request #56 from posit-conf-2023/iterations-01-runthr
Browse files Browse the repository at this point in the history
Iterations 01 runthr
  • Loading branch information
3mmaRand authored Sep 18, 2023
2 parents 23266c5 + 1bc1dfa commit 8a235be
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions 03-iteration-01.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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()`
Expand Down Expand Up @@ -84,14 +84,16 @@ and NOT

We have:

- the `apply()` family

- `group_by()` with `summarize()`

- `facet_wrap()`

- `across()` and `purrr()`

. . .
- the `apply()` family

. . .

other languages, a for loop would be right after hello world
Expand Down Expand Up @@ -303,6 +305,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.
Expand Down Expand Up @@ -582,12 +586,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

0 comments on commit 8a235be

Please sign in to comment.