Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想用R 中的字符串替换所有A' Bs 和B's 。A
A
B
我的输入是
x = "ABCDBBABDC"
我的输出应该是,
y = "BACDAABADC"
我怎么能在一行中做到这一点?
我试过sub了,但我不能做多次替换。
sub
您正在寻找chartr:
chartr
x = "ABCDBBABDC" chartr("AB", "BA", x) # [1] "BACDAABADC"