Lab 8
Load the tidyverse and the stringr::words and stringr::fruit vectors. You won’t be able to use the data() function, you’ll have to assign stringr::words to a new object.
find matches
reminder: using str_view() will help you test and build your regular expressions.
-
Find words (from the
wordsvector) that start with a vowel usingstr_subset(). You should have 175 words. -
Find words (from the
wordsvector) that end with at least 2 consecutive consonants usingstr_subset(). (Hint: thinking about matching “not”-vowels.). You should have 353 words. -
Find words (from the
wordsvector) that end with either “ing”, “ize” or “ise” usingstr_subset(). You should have 20 words.
replace
-
You decide berries cannot be singular and wish to replace every instance of “berry” with “berries” in the
fruitvector. -
replace all 5 letter words in the
wordsvector with “five” -
From the following emails, keep only the first part of the email. In other words, use regex to replace the “@something.net|com” with nothing (
"").
emails <- c("ahmad@verizon.net", "kenja@sbcglobal.net",
"arandal@comcast.net", "seanq@me.com",
"vganesh@me.com", "jcholewa@msn.com",
"jeffcovey@aol.com", "seebs@me.com",
"camenisch@msn.com", "jmcnamara@yahoo.com",
"mcraigw@live.com", "conteb@live.com")
Your final result should be:
## ahmad kenja arandal seanq vganesh jcholewa jeffcovey seebs camenisch jmcnamara mcraigw conteb
combine
- create the following tibble:
fruitibble <- tibble::tribble(
~fruit, ~origin, ~scientific_name,
"Strawberry", "frANCE", "fragaria ananassa",
"Persimmon", "China", "Diospyros kaki",
"Honeydew", "Algeria", "Cucumis MELO",
"Dragonfruit", "Central America", "Selenicereus undatus",
"LEMON", "india", "citrus Limon",
"waterMelon", "Africa", "Citrullus lanatus",
"Avocado", "Mexico", "Persea americana",
"Blackberry", "unknown", "Rosaceae Rubus",
"Banana", "papua new guinea", "Musa acuminata",
"Pineapple", "Brazil", "Ananas comosus"
)
-
Use str_to_*()function to clean make clean capitalization on thefruitibbledataframe. Using tidyverse functions and glue, create a new column calledaboutwhich includes something like “name (scientific name) is from origin”. -
instead of creating a new column, use the
glue_date()function to output only the about text into the chunk output. However, make sure your output is sorted by fruit name.