using grep with multiple entries in r to find mathcing strings -


i have searched question online seem find every answer one.

if have vector of strings:

dd <- c("sflxgrbfg_sprd_2011","sflxgrbfg_sprd2_2011","sflxgrbfg_sprd_2012") 

and want find entires '2011' in string can use

ifiles <- dd[grep("2011",dd)] 

how search entries combination of strings included, without using loop?

for example, find entries both '2011' , 'sprd' in string, in case return

sflxgrbfg_sprd_2011 

how can done? define variable

tomatch <- c('2011','sprd) 

and loop through entries hoping there better solution?

note: make useful different strings. possible to determine entries have these strings without them being in order shown. example, 'sflxlgrbfg_2011_sprd'

if want find more 1 pattern, try indexing logical value rather number. way can create "and" condition, string both patterns extracted.

ifiles <- dd[grepl("2011",dd) & grepl("sprd_",dd)] 

Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -