Practical 3
Quarto and tables
Create a new Quarto document in RStudio. Use the default format (HTML) and ensure that the document includes a title and author.
Write a short introduction (1-2 sentences) explaining the purpose of the document.
Add a Markdown section demonstrating headings, bold, italics, and lists. For example:
- Bold text
- Italic text
- A numbered list
- A bullet point list
Insert an R code chunk that calculates the mean and standard deviation of a numeric vector. Ensure the chunk is set to
echo: trueso the code appears in the rendered document.```{r} #| echo: true values <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) mean(values) sd(values) ```Modify the code chunk options:
- Add another code chunk that prints a message but set
echo: falseso the code is hidden but the output is visible.
```{r} #| echo: false print("This message is displayed, but the code is hidden.") ```- Add another code chunk that prints a message but set
Create a simple table using the
gtpackage. Load thepenguinsdataset and display a summary table ofspeciesandbill_len.```{r} #| message: false library(tidyverse) library(gt) data(penguins) penguins |> select(species, bill_len) |> head() |> gt() ```TipNote that
gtis simply converting your data frame into a HTML table; it’s not calculating anything liketbl_summary.Use the
tbl_summaryfunction from thegtsummarypackage to summarise all numeric variables in thepenguinsdataset byspecies.```{r} library(gtsummary) penguins |> select(species, where(is.numeric)) |> tbl_summary(by = species) ```Convert the document to Microsoft Word format by modifying the YAML header at the top of the document. Change
format: htmltoformat: docx.Render the document and verify that the output appears as expected.