#imports
options(repos = c(CRAN = "https://cloud.r-project.org"))
install.packages("readr")
##
## The downloaded binary packages are in
## /var/folders/01/fn2zbnk50d1c7bvpjbdfvs_w0000gn/T//Rtmp9DnMsw/downloaded_packages
install.packages("dplyr")
##
## The downloaded binary packages are in
## /var/folders/01/fn2zbnk50d1c7bvpjbdfvs_w0000gn/T//Rtmp9DnMsw/downloaded_packages
library(readr)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
#Load the CSV file from URL
url <- "https://raw.githubusercontent.com/fivethirtyeight/data/master/college-majors/majors-list.csv"
majors_df <- read_csv(url)
## 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.
#Filtering dataset
filtered_majors <- majors_df %>%
filter(grepl("DATA|STATISTICS", Major, ignore.case = TRUE))
print(filtered_majors)
## # 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
fruits <- c("bell pepper", "bilberry", "blackberry", "blood orange",
"blueberry", "cantaloupe", "chili pepper", "cloudberry",
"elderberry", "lime", "lychee", "mulberry",
"olive", "salal berry")
# Display the result
print(fruits)
## [1] "bell pepper" "bilberry" "blackberry" "blood orange" "blueberry"
## [6] "cantaloupe" "chili pepper" "cloudberry" "elderberry" "lime"
## [11] "lychee" "mulberry" "olive" "salal berry"
cat("c(", paste(shQuote(fruits, type = "cmd"), collapse = ", "), ")", sep = "")
## c("bell pepper", "bilberry", "blackberry", "blood orange", "blueberry", "cantaloupe", "chili pepper", "cloudberry", "elderberry", "lime", "lychee", "mulberry", "olive", "salal berry")
(.)\1\1
This expression matches a single character that repeats three times consecutively. For instance, “aaa”.
"(.)(.)\2\1"
This expression matches two characters (. and .) followed by the same characters in reverse order. For instance, it would match “xyyx”
(..)\1
This matches two consecutive characters (..) that are repeated in the same order. For instance, “1212”
"(.).\1.\1"
This expression matches a single character (.), followed by any character, then the first character, followed by another any character, and then the same first character again. For instance, “aba”
"(.)(.)(.).*\3\2\1"
This expression matches three distinct characters (.)(.)(.) followed by any number of characters (.*), and then the same three characters in reverse order. For instance, “xyzabczyx”
1. Start and end with the same character: \^(.)\w\*\\1\$
2. Contain a repeated pair of letters: (\w\w).\*\\1
3. Contain one letter repeated in at least three places: (.)\w\*\\1\w\*\\1