I need to filter rows from df that contain air as a stand-alone word in a column
library(dplyr)
df <- data.frame(x = c(13, 34, 5, 124, 56),
y = c('air transport', 'hairdressing', 'airport', 'repair', 'frontend'))
This gives me rows that partially contain air
df %>% filter(grepl('air',y))
x y
1 13 air transport
2 34 hairdressing
3 5 airport
4 124 repair
Here is my intended result
x y
1 13 air transport
>Solution :
Use \\b to match a zero-length word boundary:
df %>%
filter(grepl('\\bair\\b', y))