使用R将字符向量转换为字符串(带引号和逗号)

时间:2017-07-01 09:30:10

标签: mysql r

大家好paste(c("A","B","C"),collapse='","'), 输出为"A\",\"B\",\"C"

如何将"A","B","C"作为一个字符串?

1 个答案:

答案 0 :(得分:3)

即使R输出"A\",\"B\",\"C", 请记住,实际值实际上是A","B","C。 您可以通过打印值来验证这一点:

> cat(paste(c("A","B","C"),collapse='","'))
A","B","C

现在,如果您希望值为"A","B","C"而不是A","B","C, 然后你需要paste再一次",然后添加"

> cat(paste('"', paste(c("A","B","C"),collapse='","'), '"', sep=''))
"A","B","C"