I have a string like this
fileName <- 'tyi_myRef_2019_2020'
I want to check if any of the following characters
are present in the fileName
and if yes, assign it to an object.
myChar <- c('myPer','myRef','myYe','myQr')
The way I did this is:
if(grepl('myPer', fileName)) {myObject <- 'myPer'}
if(grepl('myRef', fileName)) {myObject <- 'myRef'}
if(grepl('myYe', fileName)) {myObject <- 'myYe'}
if(grepl('myQr', fileName)) {myObject <- 'myQr'}
myObject
"myRef"
Is there a shorter way to do this?