R Markdown

Question 1

library(readr)
urlfile="https://raw.githubusercontent.com/fivethirtyeight/data/refs/heads/master/college-majors/majors-list.csv"
collegemajors <- read_csv(url(urlfile))
## Rows: 174 Columns: 3
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): FOD1P, Major, Major_Category
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
collegemajors[grepl("DATA|STATISTICS", collegemajors$Major),]
## # A tibble: 3 × 3
##   FOD1P Major                                         Major_Category         
##   <chr> <chr>                                         <chr>                  
## 1 6212  MANAGEMENT INFORMATION SYSTEMS AND STATISTICS Business               
## 2 2101  COMPUTER PROGRAMMING AND DATA PROCESSING      Computers & Mathematics
## 3 3702  STATISTICS AND DECISION SCIENCE               Computers & Mathematics

Question 2

fruit <- c("bell pepper", "bilberry", "blackberry", "blood orange", "blueberry", "cantaloupe", "chili pepper", "cloudberry", "elderberry",   "lime", "lychee", "mulberry", "olive", "salal berry")
dput(fruit)
## c("bell pepper", "bilberry", "blackberry", "blood orange", "blueberry", 
## "cantaloupe", "chili pepper", "cloudberry", "elderberry", "lime", 
## "lychee", "mulberry", "olive", "salal berry")

Question 3

(.)\1\1 This expression would result in an error due to single backslashes.

“(.)(.)\2\1” This expression would show 2 characters that repeat in reverse

(..)\1 This expression needs either ’ or ” and another backslash

“(.).\1.\1” The matches would include 3 characters that are all the same with a different character between each

“(.)(.)(.).*\3\2\1” This expression is looking for 3 characters, followed by 0 or more unique letters not included in the initial 3, and then matching letters as the first group but in reverse order

Question 4

Start and end with the same character. “(.).*\1”

Contain a repeated pair of letters (e.g. “church” contains “ch” repeated twice.) “(..).*\1”

Contain one letter repeated in at least three places (e.g. “eleven” contains three “e”s.) “(.).\1.\1”