library(tidyverse)
#> Warning: package 'ggplot2' was built under R version 4.1.1
df <- tibble(x = c("apple", "deal", "panel"))
df
#> # A tibble: 3 x 1
#> x
#> <chr>
#> 1 apple
#> 2 deal
#> 3 panel
How can I do the following:
keep rows that contain "apl" i.e. apple and panel
keep rows that have "a" in the third position i.e. deal
library(tidyverse)
df <- tibble(x = c("apple", "deal", "panel", "plum", "ale"))
df
df %>% filter(str_detect(x, "^..a")|
(str_detect(x, "a") & str_detect(x, "p") & str_detect(x, "l")))
# A tibble: 3 x 1
x
<chr>
1 apple
2 deal
3 panel
There might be a way in RegEx to detect the "apl"in any order (but each at least once), but I can't think of one at the moment, so for now this one works where I test each one separately.