Skip to content

Commit

Permalink
Update index.qmd
Browse files Browse the repository at this point in the history
  • Loading branch information
trekonom committed Mar 16, 2024
1 parent 1c91324 commit fc0f367
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
4 changes: 2 additions & 2 deletions _freeze/index/execute-results/html.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"hash": "6b66cae8302b77debe544886f45671d9",
"hash": "612f49f6ca4fc9b3c71614fc22d55d29",
"result": {
"engine": "knitr",
"markdown": "---\ntitle: \"Intro-tidy\"\nformat: revealjs\nengine: knitr\nexecute: \n freeze: auto\n---\n\n\nThis is a webr-enabled code cell in a Quarto HTML document.\n\n\n::: {.cell}\n\n:::\n\n\n```{webr-r}\nggplot()\n```",
"markdown": "---\ntitle: \"Intro-tidy\"\nformat: revealjs\nengine: knitr\nexecute: \n freeze: auto\n---\n\n\n\n\n\n# tidyverse {background-color=\"aquamarine\"}\n\n> 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.\n\n## Why should we care about the tidyverse?\n\n> What's the mean of `mpg` (miles per gallon) and the number of observations by `cyl` (cylinders) in the `mtcars` dataset?\n\n::: columns\n\n::: {.column width=\"50%\"}\n#### tidyverse\n\n::: {.cell}\n\n```{.r .cell-code}\nmtcars %>%\n group_by(cyl) %>%\n summarise(mean = mean(mpg), n = n())\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n# A tibble: 3 × 3\n cyl mean n\n <dbl> <dbl> <int>\n1 4 26.7 11\n2 6 19.7 7\n3 8 15.1 14\n```\n\n\n:::\n:::\n\n:::\n\n::: {.column width=\"50%\"}\n#### base R\n\n::: {.cell}\n\n```{.r .cell-code}\nmtcars_by <- by(mtcars, mtcars$cyl, function(df) {\n with(df, data.frame(\n cyl = cyl[[1]],\n mean = mean(mpg),\n n = nrow(df)\n ))\n})\ndo.call(rbind, mtcars_by)\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n cyl mean n\n4 4 26.66364 11\n6 6 19.74286 7\n8 8 15.10000 14\n```\n\n\n:::\n:::\n\n:::\n\n:::\n\n::: aside\nAdapted from [dplyr base R](https://dplyr.tidyverse.org/articles/base.html#summarise-reduce-multiple-values-down-to-a-single-value)\n:::",
"supporting": [
"index_files"
],
Expand Down
2 changes: 1 addition & 1 deletion _quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ filters:
- webr
webr:
show-startup-message: true
packages: ["ggplot2"]
packages: ["ggplot2", "dplyr"]

47 changes: 42 additions & 5 deletions index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,49 @@ execute:
freeze: auto
---

This is a webr-enabled code cell in a Quarto HTML document.
```{r include=FALSE}
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
```{r}
library(ggplot2)
#| echo: true
mtcars %>%
group_by(cyl) %>%
summarise(mean = mean(mpg), n = n())
```
:::

::: {.column width="50%"}
#### base R
```{r}
#| echo: true
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)
```
:::

:::

```{webr-r}
ggplot()
```
::: aside
Adapted from [dplyr base R](https://dplyr.tidyverse.org/articles/base.html#summarise-reduce-multiple-values-down-to-a-single-value)
:::

0 comments on commit fc0f367

Please sign in to comment.