本文介绍了替换为"\"与"/"在r的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试用R中的"/"或"\\"替换"\".
I'm trying to replace "\" with "/" or "\\" in R.
fp = "C:\users\jordan\Documents\Computer Science\R\miscData.txt"
replace(fp, "\", "\\")
Output:
> fp = "C:\users\jordan\Documents\Computer Science\R\miscData.txt"
Error: '\u' used without hex digits in character string starting ""C:\u"
很显然,"\"是转义字符,不能以这种方式使用.有没有办法避免在R中使用"\"作为转义字符?
Obviously, "\" is an escape character and can't be used this way. Is there a way to avoid the use of "\" as an escape character in R?
推荐答案
您可以使用扫描功能.在您的示例中:
You can use the scan function. In your example:
X = scan(what="character",allowEscapes=F, nmax = 1)
"C:\users\jordan\Documents\Computer Science\R\miscData.txt"
结果:
X
[1] "C:\\users\\jordan\\Documents\\Computer Science\\R\\miscData.txt"
这篇关于替换为"\"与"/"在r的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!