[英]Error in replacing text in R
我用sub替換R中的一個文本。
x<-"My name is ${name}"
sub("${name}","Tiger",x)
錯誤信息:
Error in sub("${name}", "Tiger", x) :
invalid regular expression '${name}', reason 'Invalid contents of {}'
輸入文本有{},如何修復此錯誤?
$
, {
和}
需要轉義:
sub("\\$\\{name\\}","Tiger",x)
# [1] "My name is Tiger"
使用fixed=TRUE
參數:
sub("${name}","Tiger",x, fixed=TRUE)
# [1] "My name is Tiger"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.