library(openintro)
## Loading required package: airports
## Loading required package: cherryblossom
## Loading required package: usdata
library(tidyverse)
## Warning: package 'ggplot2' was built under R version 4.4.3
## Warning: package 'tidyr' was built under R version 4.4.3
## Warning: package 'purrr' was built under R version 4.4.3
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.1     ✔ stringr   1.6.0
## ✔ ggplot2   4.0.2     ✔ tibble    3.2.1
## ✔ lubridate 1.9.4     ✔ tidyr     1.3.2
## ✔ purrr     1.2.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
library(dplyr)

babies_summary <- babies %>%
  filter(gestation < 999) %>% 
  group_by(parity) %>%
  summarise(
    mean_gestation = mean(gestation, na.rm = TRUE),
    median_gestation = median(gestation, na.rm = TRUE),
    sd_gestation = sd(gestation, na.rm = TRUE),
    count = n()
  )

babies_summary
## # A tibble: 2 × 5
##   parity mean_gestation median_gestation sd_gestation count
##    <int>          <dbl>            <dbl>        <dbl> <int>
## 1      0           279.              279         16.6   910
## 2      1           281.              282         14.2   313


Based on the result, there is no significant difference in the average gestation length between the first time mothers and those who have been pregnant before. Both groups have the average of around 280 days.