I know from the R documentation that the gsub
function can be programmed to do simultaneous operations like upper/lowercase substitution:
gsub("([a-z]*)([A-Z]*)", "\U\1\L\2", "upper LOWER", perl=TRUE)
[1] "UPPER lower"
I have a minimal example, a string “STTS”, in which I want to replace “S” with “TRUE” and “T” with “FALSE”. I cannot do it sequentially because the matching patterns would obviously collide.
I have tried this code:
gsub("([S]*)\1([T]*)\2", "TRUE \1FALSE \2", "STTS",perl=TRUE)
and received [1] "TRUE FALSE STRUE FALSE TSTRUE FALSE "
instead of "TRUE FALSE FALSE TRUE"
user24504409 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.