diff --git a/_freeze/index/execute-results/html.json b/_freeze/index/execute-results/html.json index 16b6dcd..b64d1e5 100644 --- a/_freeze/index/execute-results/html.json +++ b/_freeze/index/execute-results/html.json @@ -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 \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" ], diff --git a/index.qmd b/index.qmd index d49a859..48f422b 100644 --- a/index.qmd +++ b/index.qmd @@ -7,6 +7,7 @@ execute: --- ```{r include=FALSE} +#| context: setup library(ggplot2) library(dplyr) ``` @@ -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()) ``` ::: @@ -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]],