in regular form if you're needing to use regex but have numerous strings you need to replace, it would look like:
mutate(chemical = str_replace(chemical, "\\-Total$", ""),
chemical = str_replace(chemical, "\\-SO4", "(SO4)"))
and in the case_when format, in order to do multiple str_replace you have to do both a str_detect and str_replace , (which is even more bulky and repetitive) like so:
in regular form if you're needing to use regex but have numerous strings you need to replace, it would look like:
and in the
case_when
format, in order to do multiplestr_replace
you have to do both astr_detect
andstr_replace
, (which is even more bulky and repetitive) like so:i'm not totally sure how it could be written out but in an ideal form, a vectorized
str_replace
would look something like:or in a
case_when
format, it would still require astr_detect
so something like: