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 31c6011 commit f9fb2a7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 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": "612f49f6ca4fc9b3c71614fc22d55d29",
"hash": "ce0a92f7bd46d1028b0205152bdfa4b8",
"result": {
"engine": "knitr",
"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:::",
"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```{webr-r}\nmtcars |> \n group_by(cyl) |> \n summarise(mean = mean(mpg), n = n())\n```\n:::\n\n::: {.column width=\"50%\"}\n\n#### base R\n\n```{webr-r}\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\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
7 changes: 3 additions & 4 deletions index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ execute:
---

```{r include=FALSE}
#| context: setup
library(ggplot2)
library(dplyr)
```
Expand All @@ -25,9 +26,8 @@ library(dplyr)
::: {.column width="50%"}
#### tidyverse
```{webr-r}
#| echo: true
mtcars %>%
group_by(cyl) %>%
mtcars |>
group_by(cyl) |>
summarise(mean = mean(mpg), n = n())
```
:::
Expand All @@ -37,7 +37,6 @@ mtcars %>%
#### base R

```{webr-r}
#| echo: true
mtcars_by <- by(mtcars, mtcars$cyl, function(df) {
with(df, data.frame(
cyl = cyl[[1]],
Expand Down

0 comments on commit f9fb2a7

Please sign in to comment.