我想将对象的某些部分放入双引号中,如下面给出的示例所示:
所需输出
"Group 1" = 3, "Group 2" = 3
MWE
Test <- structure("Group 1 = 3, Group 2 = 3", class = "noquote")
Test
[1] Group 1 = 3, Group 2 = 3
as.character(Test)
[1] "Group 1 = 3, Group 2 = 3"
被修改
实际上我有一个很长的字符串(这里是实验室)
Labs <- c("Group 1", "Group 2")
Test <- noquote(paste(Labs, "= 3", collapse = ", "))
Test
[1] Group 1 = 3, Group 2 = 3
但是,我希望有这样的输出
"Group 1" = 3, "Group 2" = 3
答案 0 :(得分:4)
您可以使用单引号让R知道字符串开头和结尾的位置。这样你就可以在里面加上双引号:
Test <- c('"Group 1" = 3', '"Group 2" = 3')
如果您print
,那么默认情况下它会向您显示转义字符。但是,根据您的需要,您可以cat
,或使用一些更高级的选项。
cat(Test)
"Group 1" = 3 "Group 2" = 3