Quiz
You have finished the text-and-time section: manipulating strings with stringr, writing regular expressions, parsing dates with lubridate, and ordered categories with forcats. This short quiz checks what stuck. Pick an answer to continue; you can retry until it clicks. The last two steps are live R, run them and tinker.
What str_detect returns
You run str_detect(c("apple", "pear", "grape"), "ap"). What comes back?
str_detect() reports whether each string contains the pattern, so you can use it to filter.str_locate(); str_detect() gives TRUE or FALSE.A digit in a regex
In an R string, how do you write the regular expression that matches a single digit?
\\ as one backslash, so the regex engine receives \d, the digit class.\\d or [0-9].First match or all of them
str_replace() and str_replace_all() differ how?
_all variant when a pattern can appear more than once.Parsing a date
You have the text "2026-03-08" and want a real date you can do arithmetic on. With lubridate, which call parses it?
ymd fits this text.What a factor's levels are
You make factor(c("low", "high", "low")). What are its levels?
Anchoring a pattern
In a regular expression, what does the ^ at the start of a pattern mean?
^abc matches only when the string begins with abc; pair it with $ to anchor the end.* or +; ^ anchors position.stringr in live R
Extract the first run of digits from each string. Run it, then change the pattern to "[a-z]+" to grab letters instead.
str_extract() returns the first match of the pattern in each string, or NA when there is none, as in the last entry.
lubridate in live R
Parse two dates and subtract them to get the gap in days. Run it, then change one date and run again.
Once text becomes a real date with ymd(), ordinary subtraction gives you a meaningful number of days.
Section complete
Nice work. You can detect and replace text with stringr, write a digit class with the doubled backslash, tell str_replace from str_replace_all, parse dates with the right lubridate function, describe a factor's levels, and anchor a pattern with ^. Next section: iteration with the apply family and purrr.