You could form a regex alternation, and then grep for that:

vec <- c("Fast.file1", "Fast.file2", "Med.file3", "Medium.file4", "Slow.file5")
checkAgainst <- c("Fast", "Medium", "Med")
regex <- paste(checkAgainst, collapse="|")
Fast_files <- vec[grep(regex, vec)]
Fast_files

[1] "Fast.file1"   "Fast.file2"   "Med.file3"    "Medium.file4"

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top