library(stringr)
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.3.6     ✔ purrr   0.3.4
## ✔ tibble  3.1.8     ✔ dplyr   1.0.9
## ✔ tidyr   1.2.0     ✔ forcats 0.5.2
## ✔ readr   2.1.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()

#1. Import Major_List into R

major_list <- read.csv(file = '/Users/joycealdrich/Documents/SPS Data Science/Data 607/Assignment_3/majors-list.csv')
head(major_list)
##   FOD1P                                 Major                  Major_Category
## 1  1100                   GENERAL AGRICULTURE Agriculture & Natural Resources
## 2  1101 AGRICULTURE PRODUCTION AND MANAGEMENT Agriculture & Natural Resources
## 3  1102                AGRICULTURAL ECONOMICS Agriculture & Natural Resources
## 4  1103                       ANIMAL SCIENCES Agriculture & Natural Resources
## 5  1104                          FOOD SCIENCE Agriculture & Natural Resources
## 6  1105            PLANT SCIENCE AND AGRONOMY Agriculture & Natural Resources
grep(pattern = 'DATA|STATISTICS', major_list$Major, value = TRUE, ignore.case = TRUE)
## [1] "MANAGEMENT INFORMATION SYSTEMS AND STATISTICS"
## [2] "COMPUTER PROGRAMMING AND DATA PROCESSING"     
## [3] "STATISTICS AND DECISION SCIENCE"

#2

fruits <- c("bell pepper", "bilberry", "blackberry", "blood orange", "blueberry", "cantaloupe", "chili pepper", "cloudberry", "elderberry", "lime", "lychee", "mulberry", "olive", "salal berry")
string_fruits <- paste('c(', paste('"',fruits,'"', sep = "",collapse =','), sep="", ')')

writeLines(string_fruits)
## c("bell pepper","bilberry","blackberry","blood orange","blueberry","cantaloupe","chili pepper","cloudberry","elderberry","lime","lychee","mulberry","olive","salal berry")

#3 (.)\1\1 >> (.)\1\1 (correct format) ## repeat char and then repeat that char again (aaa) & does not start on a new line

“(.)(.)\2\1” ## first char / second char and then in the reverse second char / first char (abba)

(..)\1 ## two chas repeated twice (abab)

“(.).\1.\1” ## chars repeated three times with one char between each (x.x.x)

“(.)(.)(.).\3\2\1” ## 3 chars in order with two chars between (.) and then in the reverse order of 3 chars (abc.*cba)

#4

x1<- c("viv", "abba", "tot", "zz")


str_view(x1, "^(.)((.*\\1$)|\\1$)")
x2 <-c("yoyo","coconut","church","coco")


str_view(x2, "([A-Za-z][A-Za-z]).*\\1")
x3 <- c("eleven", "pepper","jamaica")
str_view(x3, "([A-Za-z]).*\\1.*\\1" )