Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see https://quarto.org.
Running Code
When you click the Render button a document will be generated that includes both content and the output of embedded code. You can embed code like this:
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.5.1 ✔ tibble 3.2.1
✔ lubridate 1.9.3 ✔ tidyr 1.3.1
✔ purrr 1.0.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
You can add options to executable code like this
[1] 4
The echo: false option disables the printing of code (only output is displayed).
Fact
Spheniscus demersus is the Latin name for African penguins
library(palmerpenguins)library(tidyverse)
Libraries
library(tidyverse)library(readr)library(knitr)
Exercises W3
diamonds %>%#uses the diamond datasetgroup_by(color, clarity) %>%#groups data by variables selectedmutate(price200 =mean(price)) %>%#creates new variable in this case mean priceungroup() %>%#no longer groups datamutate(random10 =10+ price) %>%#creates new variable, increases price by 10select(clarity, cut, price, color, price200, random10) %>%#keeps only the columns listed in linearrange(color) %>%#visualises data by colourgroup_by(cut) %>%#groups data by cutmutate(dis =n_distinct(price),rowID =row_number()) %>%#counts number of unique values per cut, then numbers each row per cutungroup()
# A tibble: 53,940 × 8
clarity cut price color price200 random10 dis rowID
<ord> <ord> <int> <ord> <dbl> <dbl> <int> <int>
1 VS2 Very Good 357 D 2587. 367 5840 1
2 VS1 Very Good 402 D 3030. 412 5840 2
3 VS2 Very Good 403 D 2587. 413 5840 3
4 VS2 Good 403 D 2587. 413 3086 1
5 VS1 Good 403 D 3030. 413 3086 2
6 VS2 Premium 404 D 2587. 414 6014 1
7 SI1 Premium 552 D 2976. 562 6014 2
8 SI1 Ideal 552 D 2976. 562 7281 1
9 SI1 Ideal 552 D 2976. 562 7281 2
10 VVS1 Very Good 553 D 2948. 563 5840 4
# ℹ 53,930 more rows
`summarise()` has grouped output by 'cut'. You can override using the `.groups`
argument.
# A tibble: 35 × 4
cut color m s
<ord> <ord> <dbl> <dbl>
1 Fair D 4291. 3286.
2 Fair E 3682. 2977.
3 Fair F 3827. 3223.
4 Fair G 4239. 3610.
5 Fair H 5136. 3886.
6 Fair I 4685. 3730.
7 Fair J 4976. 4050.
8 Good D 3405. 3175.
9 Good E 3424. 3331.
10 Good F 3496. 3202.
# ℹ 25 more rows