Filtering a data frame:
df <- read.csv('https://raw.githubusercontent.com/fivethirtyeight/data/master/college-majors/majors-list.csv')
df %>%
filter(str_detect(Major, "DATA|STATISTICS"))
## FOD1P Major Major_Category
## 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
Combining a string:
str_c(c("bell pepper","bilberry","blackberry","blood orange","blueberry","cantaloupe","chili pepper","cloudberry", "olive","salal berry"), collapse=", ")
## [1] "bell pepper, bilberry, blackberry, blood orange, blueberry, cantaloupe, chili pepper, cloudberry, olive, salal berry"
One character followed by 2 matching characters
Double back slash indicates for use with str_view. Two single character group followed by matching of 2nd group letter followed by last character matching the 1st
Two character group followed by identical two character.
Double back slash indicates for use with str_view. One single character group, followed any character followed by 1st group letter follow by any letter followed by first group letter.
Double back slash indicates for use with str_view. Three single character groups followed by any character followed by matching of third group letter followed bye 2nd group letter followed by 1st group letter.
(.).*\1
(..).*\1
(.).*\1.*\1