I\'m looking to do something seemingly very simple. I would like to subset a data frame in R using the grepl() command -- or something like it -- on several different phras
You can combine your mynames
vector with the regular expression operator |
and use grep
.
tmp[grep(paste(mynames, collapse='|'), tmp$Name, ignore.case=TRUE),]
# Name Age Height
# 1 Mary Anne 31 1
# 2 Mary Smith 23 2
# 3 Potter, Mary 23 3
# 4 mary jane 55 4
# 5 Bob 32 5
# 6 bob smith 36 6
# 7 smith, BOB 45 7