R:如何更换.在字符串中? [英] R: How to replace . in a string?
本文介绍了R:如何更换.在字符串中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字符串说a.b",我想替换."和 "_".
I have a string say "a.b" and I want to replace "." with "_".
gsub(".","_","a.b")
不能作为 .匹配所有字符.
doesn't work as . matches all characters.
gsub("\.","_","a.b")
只是给我一个错误.
阅读有关 ?gsub 的文档没有多大帮助!
Reading the documentation on ?gsub is not that helpful!
那么如何做这件直截了当的事情?
So how to do this straight-forward thing?
推荐答案
.
匹配任何字符.转义 .
使用 \
匹配 .
字面意义.
.
matches any character. Escape .
using \
to match .
literally.
\
本身也是应该转义的:
\
itself is also should be escaped:
> gsub("\\.", "_", "a.b")
[1] "a_b"
这篇关于R:如何更换.在字符串中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文