Extract distinct characters that differ between two strings

Viewed 756

I have two strings, a <- "AERRRTX"; b <- "TRRA" .

I want to extract the characters in a not used in b, i.e. "ERX"

I tried the answer in Extract characters that differ between two strings , which uses setdiff. It returns "EX", because b does have "R" and setdiff will eliminate all three "R"s in a. My aim is to treat each character as distinct, so only two of the three R's in a should be eliminated.

Any suggestions on what I can use instead of setdiff, or some other approach to achieve my output?

4 Answers
Related