Вот еще одно базовое решение R путем определения вашей пользовательской функции f
в качестве фильтра, т. Е.
f <- Vectorize(function(pat) grepl(pat,do.call(paste,df)))
dfout <- subset(df,do.call(`&`,data.frame(f(c("\\bJohn\\b","\\bPeter\\b")))))
, такой что
> dfout
a1 a2 a3 a4 a5 a6 a7
2 23 67 John Phil Peter Keim Luke
4 6 57 Peter John Paul Luke Rick
DATA
df <- structure(list(a1 = c(14, 23, 24, 6, 4), a2 = c(5, 67, 4, 57,
54), a3 = structure(c(3L, 1L, 2L, 4L, 1L), .Label = c("John",
"Mike", "Paul", "Peter"), class = "factor"), a4 = structure(c(1L,
4L, 3L, 1L, 2L), .Label = c("John", "Luke", "Peter", "Phil"), class = "factor"),
a5 = structure(c(1L, 4L, 2L, 3L, 5L), .Label = c("Dave",
"Nick", "Paul", "Peter", "Phil"), class = "factor"), a6 = structure(c(1L,
2L, 5L, 3L, 4L), .Label = c("Adrian", "Keim", "Luke", "Mike",
"Rick"), class = "factor"), a7 = structure(c(4L, 3L, 1L,
4L, 2L), .Label = c("Adrian", "Dave", "Luke", "Rick"), class = "factor")), class = "data.frame", row.names = c(NA,
-5L))