在全球范围内用多种模式替换多种替代品
在 R 中,我们可以使用 gsub 将向量中的一种模式全局替换为另一种模式。但是,如果我想用许多模式替换许多模式,我该怎么做呢?例如:-
a <- c("AV. Reg", "AVENUE Reg", "Bld. Aze", "BOUlevard Aze", "Str. Fsd", "Strasse FSD", "R. Ger", "RUE Ger")
现在我想替换以下内容:-
pattern replacement
AV. Avenue
AVENUE Avenue
Bld. Boulevard
BOUlevard Boulevard
Str. Strasse
R. Rue
RUE Rue
我可以将 pattern
和 replacement
定义为两个向量并用 替换
pattern
全局替换。
提前致谢。
In R
, we can use gsub
to globally substitute one pattern by another pattern in a vector. However, if I want to substitute many patterns for many pattern, how can I do this. For ex:-
a <- c("AV. Reg", "AVENUE Reg", "Bld. Aze", "BOUlevard Aze", "Str. Fsd", "Strasse FSD", "R. Ger", "RUE Ger")
Now I want to substitute the following :-
pattern replacement
AV. Avenue
AVENUE Avenue
Bld. Boulevard
BOUlevard Boulevard
Str. Strasse
R. Rue
RUE Rue
Can I define pattern
and replacement
as two vectors and substitute pattern
by replacement
globally.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请注意,\ 是为了转义“.”。特殊字符(您可以检查删除它们后会发生什么)。另外,我改变了你的 BLD。到大厦。因为我猜你的意思是
Note the \ is to escape the "." special character ( you can check what happens if you remove them). Also, I changed your BLD. to Bld. cause I guess that what you meant