-
Notifications
You must be signed in to change notification settings - Fork 0
/
across_microflip_3.Rmd
69 lines (55 loc) · 1.64 KB
/
across_microflip_3.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
---
title: "How to Use the _across()_ function"
subtitle: "mutate or summarize across many columns at once"
author:
- "Peter Higgins"
date: '`r Sys.Date()`'
output:
xaringan::moon_reader:
lib_dir: libs
css: xaringan-themer.css
nature:
highlightStyle: github
highlightLines: true
countIncrementalSlides: false
ratio: 16:9
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(fig.width = 6, message = FALSE, warning = FALSE, comment = "", cache = FALSE, fig.retina = 3)
library(flipbookr)
library(xaringan)
library(xaringanthemer)
library(tidyverse)
library(medicaldata)
data <- medicaldata::blood_storage %>% as_tibble()
```
```{r xaringan-themer, include=FALSE, warning=FALSE}
library(xaringanthemer)
style_duo_accent(
primary_color = "#00274C",
secondary_color = "#FFCB05",
inverse_header_color = "#FFFFFF"
)
```
### How to Use Across to Act on Many Columns at Once
Format: <br>
summarize(across(logic.test = which variables, _function to apply()_))
**Example 3:** calculate multiple summary measures across several columns
We will calculate mean, median, and sd for Age, & Tumor Volume for prostate cancer
---
```{r across3, include = FALSE, eval = FALSE}
data %>%
group_by(Recurrence) %>%
# now do summarize across
summarize(across(c(Age, TVol),
list(mean = mean,
median = median,
sd = sd),
na.rm = TRUE,
.names = "{col}__{fn}"))
# Format:
# summarize(across(logic.test, function, .names))
```
`r chunk_reveal("across3",
break_type = "auto",
title = "Multiple Summary Functions Across Several Variables")`