@@ -1374,16 +1374,20 @@ region_lang |>
1374
1374
> also return ` NA ` s when we apply them to columns that
1375
1375
> contain ` NA ` s in the data frame. \index{missing data}
1376
1376
>
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
1382
1382
>
1383
1383
> ``` {r}
1384
1384
> 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) ))
1386
1386
> ```
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
+
1387
1391
1388
1392
#### `map` for calculating summary statistics on many columns {-}
1389
1393
0 commit comments