在循环内将引号粘贴到字符串中

发布于 2024-10-07 18:28:10 字数 333 浏览 0 评论 0原文

使用 R,我想生成多个字符串,例如:

"modelCheck("var1_d.bug")"  
"modelCheck("var2_d.bug")"  
...  
"modelCheck("var10_d.bug")"

我通常会使用 for 循环并粘贴(如果我不必担心双引号),如下所示:

for(i in 1:10){
    str<-paste("modelCheck(var",i,"_d.bug)",sep="")
    print(str)
}

但是,我需要将双引号包含在字符串,因此请求帮助?

Using R, I want to produce multiple character strings such as:

"modelCheck("var1_d.bug")"  
"modelCheck("var2_d.bug")"  
...  
"modelCheck("var10_d.bug")"

I would usually use a for loop and paste (if I did not have to worry about the double quotation marks) as such:

for(i in 1:10){
    str<-paste("modelCheck(var",i,"_d.bug)",sep="")
    print(str)
}

However, I need to include the double quotation marks within the character string, hence the appeal for help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

任性一次 2024-10-14 18:28:10

只需使用反斜杠转义引号

paste("modelCheck(var\"",i,"_d.bug\")",sep="")

另一种方法是使用单引号用引号将字符串括起来:

paste('modelCheck(var"',i,'_d.bug")',sep="")

Simply escape the quotation marks with backslashes:

paste("modelCheck(var\"",i,"_d.bug\")",sep="")

An alternative is to use single quotes to enclose the string:

paste('modelCheck(var"',i,'_d.bug")',sep="")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文