Publications by Joey Campbell
replace_matches42_demo
suppressPackageStartupMessages(library("tidyverse")) package 㤼㸱tidyverse㤼㸲 was built under R version 3.6.3 1. Replace all forward slashes in a string with backslashes. str_replace_all("past/present/future", "/", "\\\\") [1] "past\\present\\future" 2. Implement a simple version of str_to_lower() using replace_all(). replacements <- c( ...
2020 sym R (1381 sym/9 pcs)
grouped_matches41_demo
suppressPackageStartupMessages(library("tidyverse")) package 㤼㸱tidyverse㤼㸲 was built under R version 3.6.3 1. Find all words that come after a “number” like “one”, “two”, “three” etc. Pull out both the number and the word. numword <- "\\b(one|two|three|four|five|six|seven|eight|nine|ten) +(\\w+)" sentences[str_detect(sen...
1425 sym R (1197 sym/6 pcs)
extract_matches40_demo
suppressPackageStartupMessages(library("tidyverse")) package 㤼㸱tidyverse㤼㸲 was built under R version 3.6.3 1. In the previous example, you might have noticed that the regular expression matched “flickered”, which is not a color. Modify the regex to fix the problem. This was the original color match pattern: colours <- c("red", "orang...
5247 sym R (1357 sym/15 pcs)
repetition37_demo
suppressPackageStartupMessages(library("tidyverse")) package 㤼㸱tidyverse㤼㸲 was built under R version 3.6.3 1 Describe the equivalents of ?, +, * in {m,n} form. Pattern {m,n} Meaning ? {0,1} Match at most 1 + {1,} Match 1 or more * {0,} Match 0 or more Pattern {m,n} Meaning ? {0,1} Match at most 1 + {1,} Match 1 or more * {0,} Match 0...
5317 sym R (821 sym/14 pcs) 1 tbl
backref38_demo
suppressPackageStartupMessages(library("tidyverse")) package 㤼㸱tidyverse㤼㸲 was built under R version 3.6.3 1. Describe, in words, what these expressions will match: (.)\1\1: The same character appearing three times in a row. E.g. "aaa" "(.)(.)\\2\\1": A pair of characters followed by the same pair of characters in reversed order. E.g. "...
4153 sym R (1453 sym/12 pcs)
anchors35_demo
suppressPackageStartupMessages(library("tidyverse")) package 㤼㸱tidyverse㤼㸲 was built under R version 3.6.3 1. How would you match the literal string “\(^\)”? To check that the pattern works, I’ll include both the string “\(^\)”, and an example where that pattern occurs in the middle of the string which should not be matched. st...
2151 sym R (670 sym/8 pcs)
stringBasics33_demo
suppressPackageStartupMessages(library("tidyverse")) package 㤼㸱tidyverse㤼㸲 was built under R version 3.6.3 1. In code that doesn’t use stringr, you’ll often see paste() and paste0(). What’s the difference between the two functions? What stringr function are they equivalent to? How do the functions differ in their handling of NA? Th...
8008 sym R (1329 sym/38 pcs)
basicMatches34_demo
suppressPackageStartupMessages(library("tidyverse")) package 㤼㸱tidyverse㤼㸲 was built under R version 3.6.3 1. Explain why each of these strings don’t match a \: "\", "\\", "\\\". "\": This will escape the next character in the R string. "\\": This will resolve to \ in the regular expression, which will escape the next character in the...
2140 sym R (539 sym/5 pcs)
keys30_demo
suppressPackageStartupMessages(library("tidyverse")) package 㤼㸱tidyverse㤼㸲 was built under R version 3.6.3 suppressPackageStartupMessages(library("nycflights13")) package 㤼㸱nycflights13㤼㸲 was built under R version 3.6.3 1. Add a surrogate key to flights. I add the column flight_id as a surrogate key. I sort the data prior to maki...
171920 sym R (3510 sym/24 pcs) 3 img
filteringjoins32_demo
suppressPackageStartupMessages(library("tidyverse")) package 㤼㸱tidyverse㤼㸲 was built under R version 3.6.3 suppressPackageStartupMessages(library("nycflights13")) package 㤼㸱nycflights13㤼㸲 was built under R version 3.6.3 suppressPackageStartupMessages(library("viridis")) package 㤼㸱viridis㤼㸲 was built under R version 3.6.2 ...
17831 sym R (2468 sym/25 pcs) 1 img