Skip to content

Commit 54d31e2

Browse files
fix deprecated summarize / across syntax...
1 parent 67125a7 commit 54d31e2

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

source/wrangling.Rmd

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,16 +1374,20 @@ region_lang |>
13741374
> also return `NA`s when we apply them to columns that
13751375
> contain `NA`s in the data frame. \index{missing data}
13761376
>
1377-
> To avoid this, again we need to add the argument `na.rm = TRUE`,
1378-
> but in this case we need to use it a little bit differently.
1379-
> In this case, we need to add a `,` and then `na.rm = TRUE`,
1380-
> after specifying the function we want `summarize` + `across` to apply,
1381-
> as illustrated below:
1377+
> To resolve this issue, again we need to add the argument `na.rm = TRUE`.
1378+
> But in this case we need to use it a little bit differently:
1379+
> we write a `~`, and then call the summary function
1380+
> with the first argument `.x` and the second argument `na.rm = TRUE`.
1381+
> For example, for the previous example with the `max` function, we would write
13821382
>
13831383
> ``` {r}
13841384
> region_lang_na |>
1385-
> summarize(across(mother_tongue:lang_known, max, na.rm = TRUE))
1385+
> summarize(across(mother_tongue:lang_known, ~ max(.x, na.rm = TRUE)))
13861386
> ```
1387+
> The meaning of this unusual syntax is a bit beyond the scope of this book,
1388+
> but interested readers can look up *anonymous functions* in the `purrr`
1389+
> package from `tidyverse`.
1390+
13871391
13881392
#### `map` for calculating summary statistics on many columns {-}
13891393

0 commit comments

Comments
 (0)