有人知道我该如何替换r中的“ \”?
其他答案发表了类似的内容:
l <- "1120190\neconomic"
gsub("\\", "", l, fixed=TRUE)
但在我的情况下不起作用。
您需要转义反斜杠,并在fixed=TRUE
中使用gsub
:
s <- "first \\ second \\ third \\ multiple of them \\\\\\\\ \\ \\"
gsub("\\", "!", s, fixed=TRUE)
[1] "first ! second ! third ! multiple of them !!!! ! !"