1.

load majors data, and install tidyverse:

majors <- read.csv("majors-list.csv", header=TRUE, stringsAsFactors=FALSE)
install.packages("tidyverse", repos = "http://cran.us.r-project.org")
## Installing package into 'C:/Users/guill/AppData/Local/R/win-library/4.3'
## (as 'lib' is unspecified)
## package 'tidyverse' successfully unpacked and MD5 sums checked
## 
## The downloaded binary packages are in
##  C:\Users\guill\AppData\Local\Temp\Rtmp8YlZUV\downloaded_packages
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.4.4     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.1
## ✔ purrr     1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors

majors that contain either “DATA” or “STATISTICS”:

str_view(majors$Major, "DATA|STATISTICS")
## [44] │ MANAGEMENT INFORMATION SYSTEMS AND <STATISTICS>
## [52] │ COMPUTER PROGRAMMING AND <DATA> PROCESSING
## [59] │ <STATISTICS> AND DECISION SCIENCE

2.

START:

x <-
'[1] "bell pepper"  "bilberry"     "blackberry"   "blood orange"
[5] "blueberry"    "cantaloupe"   "chili pepper" "cloudberry"  
[9] "elderberry"   "lime"         "lychee"       "mulberry"    
[13] "olive"        "salal berry"'

transformations:

test <- str_remove_all(x, '\\d')
test <- str_remove_all(test, '\\[')
test <- str_remove_all(test, '\\]')
test <- str_remove_all(test, '\\\\')
test <- str_replace_all(test, '\\s+', "\\, ")
test <- str_replace(test, '\\, ','c(')
test <- str_c(test,')')
test
## [1] "c(\"bell, pepper\", \"bilberry\", \"blackberry\", \"blood, orange\", \"blueberry\", \"cantaloupe\", \"chili, pepper\", \"cloudberry\", \"elderberry\", \"lime\", \"lychee\", \"mulberry\", \"olive\", \"salal, berry\")"

GOAL:

desiredOutput = 'c("bell pepper", "bilberry", "blackberry", "blood orange", "blueberry", "cantaloupe", "chili pepper", "cloudberry", "elderberry", "lime", "lychee", "mulberry", "olive", "salal berry")'
desiredOutput
## [1] "c(\"bell pepper\", \"bilberry\", \"blackberry\", \"blood orange\", \"blueberry\", \"cantaloupe\", \"chili pepper\", \"cloudberry\", \"elderberry\", \"lime\", \"lychee\", \"mulberry\", \"olive\", \"salal berry\")"

3.

a. (.)\1\1 --  the same three characters like AAA
b. "(.)(.)\\2\\1" --  two characters and then reversed, like ABBA
c. (..)\1 -- group of two characters repeated, like ABAB
d. "(.).\\1.\\1" -- two characters, and then a third with the first on each side like "ABACA
e. "(.)(.)(.).*\\3\\2\\1" -- atleast three chars and ending reversed like "ABCXXXXXXCBA"

4.

Start and end with the same character:

^(.).*\1$

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

([a-zA-Z][a-zA-Z]).*\1

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

([a-zA-Z]).\1.\1