I would like to have a function in R that inserts dots (".") around a given substring (e.g. "alpha") if they are not already present. E.g.
string="10-alpha-epoxy-Amorph-4-ene"
should return
"10-.alpha.-epoxy-Amorph-4-ene"
string="alpha-cadolene"
should return
".alpha.-cadolene"
but
string=".alpha.-cadolene"
should return
".alpha.-cadolene"
(the substring could occur multiple times)
What would be the easiest way to accomplish this using gsub in R?
cheers, Tom
I would do something like this :
EDIT Generalization to many terms:
In case you have a list of terms , you can use create tour regular expression using
paste
:EDIT get the list of greels in full letter: