load packages needed
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.2 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.2 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.1
## ── 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
read the birthweight data
birthweight <- read.csv("data/birthweight_data.csv")
calculate the mean birthweight separately for twins and
singletons
birthweight_summary <- birthweight %>%
group_by(plurality) %>%
summarise(
mean_weight = mean(birthweight),
sd_weight = sd(birthweight)
) %>%
ungroup ()
view the output table
birthweight_summary
## # A tibble: 2 × 3
## plurality mean_weight sd_weight
## <chr> <dbl> <dbl>
## 1 singleton 3248. 570.
## 2 twin 2311. 593.
5. identify the earliest (i.e. the minimum value) gestational age
for each ethicity group
earliest_gestational <- birthweight %>%
group_by(child_ethn) %>%
summarise(
min_gestational = min(as.numeric(gestation_age_w), na.rm = TRUE)
) %>%
ungroup ()
## Warning: There were 2 warnings in `summarise()`.
## The first warning was:
## ℹ In argument: `min_gestational = min(as.numeric(gestation_age_w), na.rm =
## TRUE)`.
## ℹ In group 3: `child_ethn = "Caucasian"`.
## Caused by warning:
## ! NAs introduced by coercion
## ℹ Run `dplyr::last_dplyr_warnings()` to see the 1 remaining warning.
view output table
earliest_gestational
## # A tibble: 10 × 2
## child_ethn min_gestational
## <chr> <dbl>
## 1 Aboriginal/Torres Strait Islander 33
## 2 African/African-American 26
## 3 Caucasian 26
## 4 East Asian 33
## 5 Hispanic/Latino 37
## 6 Middle-Eastern 28
## 7 Missing 36
## 8 Polynesian/Melanesian 28
## 9 South Asian 28
## 10 South-East Asian 29
7. download a picture of a baby from the internet and insert it into
your document below
Baby
write summary to file
write_csv(birthweight_summary, "mean_birthweight_summary.csv")
Knit document and publish to RPubs