-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.qmd
55 lines (42 loc) · 1.07 KB
/
index.qmd
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
---
title: "Intro-tidy"
format: revealjs
engine: knitr
execute:
freeze: auto
---
```{r include=FALSE}
#| context: setup
library(ggplot2)
library(dplyr)
```
# tidyverse {background-color="aquamarine"}
> The [tidyverse](https://www.tidyverse.org) is an opinionated collection of R packages designed for data science. All packages share an underlying design philosophy, grammar, and data structures.
## Why should we care about the tidyverse?
> What's the mean of `mpg` (miles per gallon) and the number of observations by `cyl` (cylinders) in the `mtcars` dataset?
::: columns
::: {.column width="50%"}
#### tidyverse
```{webr-r}
mtcars |>
group_by(cyl) |>
summarise(mean = mean(mpg), n = n())
```
:::
::: {.column width="50%"}
#### base R
```{webr-r}
mtcars_by <- by(mtcars, mtcars$cyl, function(df) {
with(df, data.frame(
cyl = cyl[[1]],
mean = mean(mpg),
n = nrow(df)
))
})
do.call(rbind, mtcars_by)
```
:::
:::
::: aside
Adapted from [dplyr base R](https://dplyr.tidyverse.org/articles/base.html#summarise-reduce-multiple-values-down-to-a-single-value)
:::