Home > Net >  R: extract an element after a symbol "="
R: extract an element after a symbol "="

Time:03-31

i have an example like this :

M01287=Neuro D

and I want to extract only one element after "=" : 'Neuro'

i tried this command, but it gives me everything after "=" :

sub('.*=', '', data$V4) -> Neuro D

Do you have a suggestion! thank you in advance

CodePudding user response:

You can add a second condition to remove everything after space :

gsub('.*=| .*', '', 'M01287=Neuro D')
  •  Tags:  
  • r
  • Related