Let’s analyze the set of names given to children born in 2017. To answer this question, you’ll need make a vector that contains every name from 2017. You can do this either with filter() or with pull() from dplyr.

babynames_2017 <- babynames %>%
  filter(year == 2017) %>%
  pull(name)

a.Which vowel is the most common in the first letter of names from 2017? Answer: The vowel A

sum(str_detect(babynames_2017,"^A"))
## [1] 4501
sum(str_detect(babynames_2017,"^E"))
## [1] 1503
sum(str_detect(babynames_2017,"^I"))
## [1] 630
sum(str_detect(babynames_2017,"^O"))
## [1] 409
sum(str_detect(babynames_2017,"^U"))
## [1] 73

b.Do more people name their children names that are longer than 5 letters or shorter than 5 letters? Answer: More people name their children names that are longer than 5 letters.

mean(str_detect(babynames_2017, "......"))
## [1] 0.6677446
mean(str_detect(babynames_2017, "^....$") + 
       str_detect(babynames_2017, "^...$") + 
       str_detect(babynames_2017, "^..$") + 
       str_detect(babynames_2017, "^.$"))
## [1] 0.1111214

c.What are the names that have at least 14 letters? Don’t use str_length().

str_view(babynames_2017, "..............", match=TRUE)

d.What names have more than two vowels in a row?

str_subset(babynames_2017, "[aeiouAEIOU]{3,}", negate=FALSE)
##   [1] "Leia"         "Kaia"         "Maia"         "Alaia"        "Louisa"      
##   [6] "Louise"       "Zoie"         "Saoirse"      "Amaia"        "Queen"       
##  [11] "Elouise"      "Theia"        "Precious"     "Aoife"        "Anaiah"      
##  [16] "Gaia"         "Caia"         "Naia"         "Khloee"       "Sequoia"     
##  [21] "Aleia"        "Zoee"         "Leiana"       "Louella"      "Leeann"      
##  [26] "Laia"         "Aleeah"       "Leiah"        "Zoei"         "Beau"        
##  [31] "Chloee"       "Zooey"        "Queenie"      "Kyliee"       "Leeanna"     
##  [36] "Beautiful"    "Joie"         "Kaiah"        "Maiah"        "Naiomi"      
##  [41] "Aletheia"     "Leianna"      "Amaiah"       "Astraea"      "Micaiah"     
##  [46] "Alaiah"       "Chloie"       "Khloie"       "Leeah"        "Aairah"      
##  [51] "Kaleia"       "Daiana"       "Raeann"       "Maleia"       "Ellieana"    
##  [56] "Jaia"         "Ellieanna"    "Queena"       "Arieanna"     "Duaa"        
##  [61] "Adaiah"       "Leeana"       "Mariaelena"   "Adaia"        "Naiara"      
##  [66] "Gioia"        "Julieanna"    "Zoii"         "Aaira"        "Julieann"    
##  [71] "Aleiah"       "Aubriee"      "Avaiah"       "Jaionna"      "Kaiulani"    
##  [76] "Anaia"        "Margeaux"     "Zaia"         "Analeia"      "Charliee"    
##  [81] "Kloie"        "Raeanna"      "Lillieann"    "Meia"         "Sanaii"      
##  [86] "Beaux"        "Jaielle"      "Juneau"       "Kaoir"        "Keiara"      
##  [91] "Laiana"       "Malaiah"      "Reia"         "Saraiah"      "Ameia"       
##  [96] "Annaleia"     "Aoi"          "Brieanna"     "Deaira"       "Keianna"     
## [101] "Maleiah"      "Naeemah"      "Raeanne"      "Ryliee"       "Zaiah"       
## [106] "Andreea"      "Caoimhe"      "Cataleia"     "Kaleiah"      "Keiana"      
## [111] "Leiani"       "Michaiah"     "Niaomi"       "Raia"         "Aaima"       
## [116] "Ameiah"       "Beauty"       "Jaiana"       "Journiee"     "Maleea"      
## [121] "Saia"         "Cloie"        "Ellieann"     "Ellouise"     "Ioanna"      
## [126] "Isabeau"      "Jaianna"      "Kloee"        "Laiah"        "Lillieanna"  
## [131] "Linnaea"      "Louann"       "Manaia"       "Mariaisabel"  "Miaisabella" 
## [136] "Miia"         "Roaa"         "Zoiee"        "Aailyah"      "Ariea"       
## [141] "Azaiah"       "Breeanna"     "Cassiopeia"   "Daia"         "Jaiah"       
## [146] "Jaleeah"      "Kalaiah"      "Kataleia"     "Keaira"       "Kelaiah"     
## [151] "Maui"         "Teia"         "Troian"       "Aaisha"       "Ariee"       
## [156] "Caiah"        "Charleeann"   "Delaia"       "Eleia"        "Gracieann"   
## [161] "Janaiah"      "Kaionna"      "Khloei"       "Kylieann"     "Leea"        
## [166] "Loie"         "Maiana"       "Makaia"       "Maleeah"      "Raea"        
## [171] "Taia"         "Taleia"       "Xoie"         "Aaiza"        "Alaiia"      
## [176] "Amaiia"       "Amiee"        "Araia"        "Arieonna"     "Breeann"     
## [181] "Jaleia"       "Joei"         "Journeii"     "Judaea"       "Kaianna"     
## [186] "Kaior"        "Kaliee"       "Kayleeann"    "Kayliee"      "Leeani"      
## [191] "Leialoha"     "Malaia"       "Mariaeduarda" "Naairah"      "Saraia"      
## [196] "Seraiah"      "Soleia"       "Aleea"        "Alieah"       "Arieana"     
## [201] "Azaleia"      "Charlieann"   "Gorgeous"     "Julieanne"    "Kaileia"     
## [206] "Kaleea"       "Kaleeah"      "Kiiara"       "Laiani"       "Laianna"     
## [211] "Laionna"      "Leauna"       "Lillieanne"   "Maliea"       "Miaa"        
## [216] "Naeema"       "Naiah"        "Oliviaann"    "Righteous"    "Sadieann"    
## [221] "Shaia"        "Sieanna"      "Victorious"   "Aiana"        "Aliaa"       
## [226] "Allieanna"    "Amariee"      "Amiaa"        "Andreia"      "Araiah"      
## [231] "Ariaunna"     "Avaia"        "Beauti"       "Briea"        "Chloeann"    
## [236] "Deairra"      "Ellalouise"   "Eviee"        "Gracious"     "Harmoniee"   
## [241] "Ioana"        "Jaleiah"      "Jameia"       "Kaiana"       "Kaliea"      
## [246] "Karliee"      "Kayleeana"    "Khaia"        "Leaira"       "Leeanne"     
## [251] "Leeasia"      "Leeila"       "Louie"        "Louisiana"    "Marylouise"  
## [256] "Meeah"        "Meiah"        "Naeomi"       "Quiana"       "Raeah"       
## [261] "Raiana"       "Siouxsie"     "Sueann"       "Thaleia"      "Zeruiah"     
## [266] "Aaila"        "Aaishah"      "Aliea"        "Analeiah"     "Ariauna"     
## [271] "Asaiah"       "Astraia"      "Aubreeanna"   "Aubrieana"    "Baia"        
## [276] "Breea"        "Breeah"       "Caliee"       "Daianna"      "Elaia"       
## [281] "Ellieanne"    "Isaiah"       "Izaiah"       "Jakaia"       "Kamaia"      
## [286] "Katieann"     "Kawaii"       "Keairra"      "Keeana"       "Keionna"     
## [291] "Kenzliee"     "Kleio"        "Kueen"        "Leeona"       "Louanna"     
## [296] "Louellen"     "Louiza"       "Makaiah"      "Mariaines"    "Mariea"      
## [301] "Marquia"      "Mireia"       "Naailah"      "Navaiah"      "Reiana"      
## [306] "Ryleeann"     "Saiah"        "Samaia"       "Sereia"       "Sophiee"     
## [311] "Talaia"       "Zaleia"       "Zaraiah"      "Zoeii"        "Isaiah"      
## [316] "Beau"         "Louis"        "Ezequiel"     "Isaias"       "Izaiah"      
## [321] "Louie"        "Kiaan"        "Riaan"        "Benaiah"      "Beaux"       
## [326] "Oseias"       "Viaan"        "Deion"        "Caius"        "Micaiah"     
## [331] "Kaius"        "Azaiah"       "Aaiden"       "Asaiah"       "Makaio"      
## [336] "Naeem"        "Keion"        "Joao"         "Eian"         "Beauregard"  
## [341] "Saeed"        "Bauer"        "Zacchaeus"    "Lucious"      "Eoin"        
## [346] "Maui"         "Jaceion"      "Mathieu"      "Iain"         "Mikaeel"     
## [351] "Jacquees"     "Octavious"    "Beauden"      "Gaius"        "Ioannis"     
## [356] "Ziaire"       "Dontavious"   "Esaias"       "Jayceion"     "Leeam"       
## [361] "Caio"         "Ismaeel"      "Thelonious"   "Quaid"        "Thaddaeus"   
## [366] "Zaeem"        "Kaiel"        "Montavious"   "Jamarious"    "Kaeo"        
## [371] "Martavious"   "Matthieu"     "Demetrious"   "Ezequias"     "Izaias"      
## [376] "Keian"        "Sequoia"      "Beaumont"     "Esequiel"     "Kaion"       
## [381] "Luian"        "Cuauhtemoc"   "Darious"      "Deaaron"      "Jasaiah"     
## [386] "Kentavious"   "Quintavious"  "Jaion"        "Jesaiah"      "Reuel"       
## [391] "Alieu"        "Daveion"      "Jedaiah"      "Kaio"         "Raoul"       
## [396] "Aous"         "Deaundre"     "Eion"         "Euan"         "Kahiau"      
## [401] "Kauan"        "Keean"        "Righteous"    "Deaire"       "Fouad"       
## [406] "Issaiah"      "Kyriee"       "Shoaib"       "Aeon"         "Faaiz"       
## [411] "Furious"      "Isaia"        "Javeion"      "Jiaan"        "Jiaire"      
## [416] "Leeum"        "Miqueas"      "Mouad"        "Quantavious"  "Shuaib"      
## [421] "Siaosi"       "Zaiah"        "Ziair"        "Aceion"       "Adaiah"      
## [426] "Hieu"         "Iaan"         "Ikaia"        "Ioane"        "Jaquavious"  
## [431] "Joeangel"     "Josaiah"      "Julious"      "Loui"         "Malaquias"   
## [436] "Moaaz"        "Muaaz"        "Yedaiah"      "Zaion"        "Adriaan"     
## [441] "Aiiden"       "Aveion"       "Ezaiah"       "Isaiahs"      "Kaien"       
## [446] "Leeon"        "Marceau"      "Mataio"       "Naiem"        "Nyzaiah"     
## [451] "Raees"        "Ruairi"       "Saliou"       "Aliou"        "Artavious"   
## [456] "Christiaan"   "Daouda"       "Izaeah"       "Jaiceion"     "Joaopedro"   
## [461] "Kaia"         "Makaius"      "Mikaiah"      "Noaah"        "Princeisaiah"
## [466] "Saia"         "Victorious"   "Aion"         "Alioune"      "Antaeus"     
## [471] "Antavious"    "Antonious"    "Aoun"         "Azarious"     "Braian"      
## [476] "Cortavious"   "Damarious"    "Dieudonne"    "Elioenai"     "Jacieon"     
## [481] "Jaeon"        "Jaiel"        "Jatavious"    "Jayveion"     "Joaolucas"   
## [486] "Kashious"     "Leeandre"     "Leiam"        "Loai"         "Louay"       
## [491] "Maaseiah"     "Marquee"      "Marquies"     "Saied"        "Saviour"     
## [496] "Taeo"         "Aaidyn"       "Areion"       "Beauman"      "Breion"      
## [501] "Daian"        "Dameion"      "Daoud"        "Darrious"     "Deian"       
## [506] "Deionte"      "Jaycieon"     "Kaceion"      "Kaian"        "Keionte"     
## [511] "Kiean"        "Leoul"        "Marquavious"  "Michaiah"     "Muaath"      
## [516] "Rontavious"   "Saair"        "Savieon"      "Siosiua"      "Tavious"     
## [521] "Zadquiel"

Are there any names with more than three vowels in a row?

str_view(babynames_2017, "[aeiouAEIOU]{4,}", match=TRUE)

e.What names contain the longest sequential string of consonants?

str_view(babynames_2017, "[^aeiouAEIOU]{8,}", match=TRUE)

In the most recent year recorded in the dataset (2017), what are the 10 most popular names that start with Z? What about the letter Q?

babynames_20172 <- babynames %>%
  filter(year == 2017) %>%
  select(name, n)

babynames_20172 %>%
  filter(str_detect(name, "^Z")) %>%
   arrange(desc(n)) %>%
    slice(1:10) 
## # A tibble: 10 x 2
##    name        n
##    <chr>   <int>
##  1 Zoey     6026
##  2 Zoe      5129
##  3 Zachary  3779
##  4 Zayden   2056
##  5 Zion     1956
##  6 Zane     1938
##  7 Zander   1546
##  8 Zara     1149
##  9 Zayn      988
## 10 Zuri      847
babynames_20172 %>%
  filter(str_detect(name,"^Q")) %>%
   arrange(desc(n)) %>%
    slice(1:10) 
## # A tibble: 10 x 2
##    name        n
##    <chr>   <int>
##  1 Quinn    3575
##  2 Quinn     892
##  3 Quentin   518
##  4 Quinton   502
##  5 Quincy    431
##  6 Queen     234
##  7 Quintin   194
##  8 Quincy    166
##  9 Quinten   132
## 10 Quinley    59

What names from 2017 have the highest number of vowels? How many names end in vowels? Answer: The name Mariaguadalupe has the most vowels. 14,275 names end in vowels.

num_vowels <- str_count(babynames_2017, "[aeiouAEIOU]")
max_vowels <- max(num_vowels)
babynames_2017[num_vowels == max_vowels]
## [1] "Mariaguadalupe"
sum(str_detect(babynames_2017, "[aeiouAEIOU]$"))
## [1] 14275

The name “Mary” was the most popular girls name from 1880-1946. Track the popularity of the name overtime using a line graph. Hint: filter for only female instances of Mary for a clearer graph. What do you notice? Answer: In 2017 it is the lowest that it has ever been. I think that is because in today’s culture, people are seeking names that are more uncommon to promote individuality. I also think the name Mary had two big spikes, the first being during the post WWI baby boom, around 1918-1929 and then during the post WWII baby boom, around 1946-1964, when people were just having more babies in general. a.What is the most popular female name in 2017? Track that name’s popularity over time. Answer: Emma

babynames %>%
  filter(sex == "F", name == "Mary") %>%
  ggplot(aes(x = year, y = n)) +
  labs(title = "Popularity of the Name Mary",
       subtitle = "From 1880-2017") +
  xlab("Year") + ylab("Number of Babies") +
  geom_line() +
  scale_x_continuous(breaks=seq(1880, 2017, 10))

babynames %>%
  filter(sex == "F", year == 2017) %>%
  top_n(1, n)
## # A tibble: 1 x 5
##    year sex   name      n   prop
##   <dbl> <chr> <chr> <int>  <dbl>
## 1  2017 F     Emma  19738 0.0105
babynames %>%
  filter(sex == "F", name == "Emma") %>%
  ggplot(aes(x = year, y = n)) +
  labs(title = "Popularity of the Name Emma",
       subtitle = "From 1880-2017") +
  xlab("Year") + ylab("Number of Babies") +
  geom_line() +
  scale_x_continuous(breaks=seq(1880, 2017, 10))

Peyton is a name that is used for both girls and boys. Plot the popularity of the name by gender. What do you notice? Answer: Peyton started out as a Male name and then was introduced as a Female name around 1957. It was pretty compairable as a female or male name up until arounf 2007 when it had a surge in popularity as a female name.

babynames %>%
  filter(name == "Peyton") %>%
  ggplot(aes(x = year, y = n, color = sex)) +
  labs(title = "Popularity of the Name Peyton",
       subtitle = "From 1880-2017 by Gender") +
  xlab("Year") + ylab("Number of Babies") +
  geom_line() +
  scale_x_continuous(breaks=seq(1880, 2017, 10))