I have the following dataframe
ColumnA=c("Kuala Lumpur Sector 2 new","old Jakarta Sector31", "Sector 9, 7 Hong Kong","Jakarta new Sector22")
and am extracting the Sector number to a separate column
gsub(".*Sector ?([0-9]+).*","\\1",ColumnA)
Is there a more elegant way to capture errors if 'Sector' does not appear on one line than an if else statement?
If the word 'Sector' does not appear on one line I simply want to set the value of that row to blank.
I thought of using str_detect first to see if 'Sector' was there TRUE/FALSE, but this is quite an ugly solution.
Thanks for any help.