fruit <- c("apple", "banana", "pear", "pineapple")
str_subset(fruit, "a")
str_subset(fruit, "^a")
str_subset(fruit, "a$")
str_subset(fruit, "b")
str_subset(fruit, "[aeiou]")
# Elements that don't match
str_subset(fruit, "^p", negate = TRUE)
# Missings never match
str_subset(c("a", NA, "b"), ".")
Run the code above in your browser using DataLab