Skip to content

Commit

Permalink
Add gut check
Browse files Browse the repository at this point in the history
  • Loading branch information
avahoffman committed Oct 10, 2024
1 parent 71eafb6 commit 1c5cda3
Showing 1 changed file with 5 additions and 34 deletions.
39 changes: 5 additions & 34 deletions modules/Functions/Functions.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ er %>%
))
```


## Applying functions with `across` from `dplyr`

Using different `tidyselect()` options (e.g., `starts_with()`, `ends_with()`, `contains()`)
Expand All @@ -376,20 +375,6 @@ er %>%
summarize(across(contains("cl"), mean, na.rm=T))
```


<!-- ## Applying functions with `across` from `dplyr`{.codesmall} -->

<!-- `mutate()` across to round across many columns at once! -->

<!-- ```{r} -->
<!-- calenviroscreen %>% -->
<!-- mutate(across( -->
<!-- where(is.numeric), -->
<!-- function(x) round(x, digits = 0) -->
<!-- )) %>% select(7:13) -->
<!-- ``` -->


## Applying functions with `across` from `dplyr` {.smaller}

Combining with `mutate()` - the `replace_na` function
Expand All @@ -409,29 +394,15 @@ yearly_co2 %>%
))
```

## GUT CHECK!

<!-- ## Use custom functions within `mutate` and `across` -->
Why use `across()`?

<!-- If your function needs to span more than one line, better to define it first before using inside `mutate()` and `across()`. -->
A. Efficiency - faster and less repetitive

<!-- ```{r} -->
<!-- times1000 <- function(x) x * 1000 -->

<!-- airquality %>% -->
<!-- mutate(across( -->
<!-- everything(), -->
<!-- .fns = times1000 -->
<!-- )) %>% -->
<!-- head(n = 2) -->

<!-- airquality %>% -->
<!-- mutate(across( -->
<!-- everything(), -->
<!-- .fns = function(x) x * 1000 -->
<!-- )) %>% -->
<!-- head(n = 2) -->
<!-- ``` -->
B. Calculate the cross product

C. Connect across datasets

## `purrr` package

Expand Down

0 comments on commit 1c5cda3

Please sign in to comment.