df <- read.csv("https://raw.githubusercontent.com/fivethirtyeight/data/master/college-majors/majors-list.csv")
selected_majors <- df[grep("DATA|STATISTICS", df$Major, ignore.case = TRUE), ]
print(selected_majors[c("FOD1P", "Major", "Major_Category")])
## FOD1P Major Major_Category
## 44 6212 MANAGEMENT INFORMATION SYSTEMS AND STATISTICS Business
## 52 2101 COMPUTER PROGRAMMING AND DATA PROCESSING Computers & Mathematics
## 59 3702 STATISTICS AND DECISION SCIENCE Computers & Mathematics
fruits <- c("bell pepper", "bilberry", "blackberry", "blood orange",
"blueberry", "cantaloupe", "chili pepper", "cloudberry",
"elderberry", "lime", "lychee", "mulberry",
"olive", "salal berry")
print(fruits)
## [1] "bell pepper" "bilberry" "blackberry" "blood orange" "blueberry"
## [6] "cantaloupe" "chili pepper" "cloudberry" "elderberry" "lime"
## [11] "lychee" "mulberry" "olive" "salal berry"
(.)\1\1: This matches any character (.) followed by itself twice. So any three identical characters in a row, like “aaa” or “111”.
“(.)(.)\2\1”: This matches any two characters where the first character is followed by a different second, and then those two are repeated in reverse order. This would match strings.
(..)\1: This matches any sequence of two characters followed by the exact same sequence.
“(.).\1.\1”: matches a pattern where a character (.) is followed by any character (which is not captured), followed by the first captured character again, another non-captured character, and then the first captured character again. It matches a string.
“(.)(.)(.).\3\2\1”: This matches a pattern of any three characters followed by any number of characters (including none, because of .), and then those first three characters in reverse order. This also captures strings.
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