2. Tidyverse worflow

[36]:
options(warn=-1)
options(messages=-1)
options(tidyverse.quiet = TRUE)
options(dplyr.summarise.inform = FALSE)
shhh <- suppressWarnings # It's a library, so shhh!
shhh(library(tidyverse))
[7]:
## ---------------------------------------------------------------------------------------------------
vow.dur <- read.table("https://bit.ly/2Iw7kn7", header=TRUE, sep="\t")
[23]:
# main dplyr functions
vow.dur %>%
  filter(context == "voiceless" & Vow_dur_ms > mean(Vow_dur_ms, na.rm = TRUE)) %>%
  arrange(desc(Vow_dur_ms)) %>%
#   select(contains("_")) %>%
# explain why some vow_dur > mean
  mutate(mean_vow_dur = mean(Vow_dur_ms, na.rm = TRUE)) %>%
  rename(vowel_duration = Vow_dur_ms)
A data.frame: 7 × 6
vowelUS_statepositioncontextvowel_durationmean_vow_dur
<fct><fct><fct><fct><dbl><dbl>
NorthCCcontextvoiceless216.6203.9143
æ NorthCCcontextvoiceless214.8203.9143
NorthCVemph voiceless209.2203.9143
æ NorthCVemph voiceless202.7203.9143
æ Ohio Ccontextvoiceless198.5203.9143
e NorthCCcontextvoiceless193.9203.9143
e NorthCVemph voiceless191.7203.9143
[37]:
# advanced dplyr functions

vow.dur %>%
  group_by(US_state, context) %>%
  summarise(mean = mean(Vow_dur_ms))
A grouped_df: 6 × 3
US_statecontextmean
<fct><fct><dbl>
NorthCvoiced 235.74
NorthCvoiceless186.26
Ohio voiced 213.90
Ohio voiceless156.94
Wisc voiced 194.59
Wisc voiceless147.14