-1

Given:

V1 <- c("abcd", "efgh", "ijkl", "mnop", "qrst")
V2 <- c("ab", "fg", "op")

Is there a R function to get

V3 <- string_fxn(V1, V2)

Such that

V3 = c("abcd", "efgh", "mnop")
camille
  • 16,432
  • 18
  • 38
  • 60
David Lee
  • 27
  • 3
  • Possible duplicate of [grep using a character vector with multiple patterns](https://stackoverflow.com/questions/7597559/grep-using-a-character-vector-with-multiple-patterns) – camille Oct 25 '19 at 16:44

1 Answers1

0

An option is grep from base R

grep(paste(V2, collapse="|"), V1, value = TRUE)
#[1] "abcd" "efgh" "mnop"
akrun
  • 874,273
  • 37
  • 540
  • 662