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)
| vowel | US_state | position | context | vowel_duration | mean_vow_dur |
|---|---|---|---|---|---|
| <fct> | <fct> | <fct> | <fct> | <dbl> | <dbl> |
| aɪ | NorthC | Ccontext | voiceless | 216.6 | 203.9143 |
| æ | NorthC | Ccontext | voiceless | 214.8 | 203.9143 |
| aɪ | NorthC | Vemph | voiceless | 209.2 | 203.9143 |
| æ | NorthC | Vemph | voiceless | 202.7 | 203.9143 |
| æ | Ohio | Ccontext | voiceless | 198.5 | 203.9143 |
| e | NorthC | Ccontext | voiceless | 193.9 | 203.9143 |
| e | NorthC | Vemph | voiceless | 191.7 | 203.9143 |
[37]:
# advanced dplyr functions
vow.dur %>%
group_by(US_state, context) %>%
summarise(mean = mean(Vow_dur_ms))
| US_state | context | mean |
|---|---|---|
| <fct> | <fct> | <dbl> |
| NorthC | voiced | 235.74 |
| NorthC | voiceless | 186.26 |
| Ohio | voiced | 213.90 |
| Ohio | voiceless | 156.94 |
| Wisc | voiced | 194.59 |
| Wisc | voiceless | 147.14 |