首页 > 解决方案 > 为特定列的每一行添加引号

问题描述

具有这种格式的数据框:

data.frame(id = c(4,2), text = c("my text here", "another text here"))

如何在文本列中每个值/行的开头和结尾添加三重引号。预期的打印输出:

id text
4 """my text here"""
2 """another text here"""

标签: r

解决方案


没有paste也不cat/paste你可以简单地运行:

data.frame(id = c(4,2), text = c('"""my text here"""', '"""another text here"""'))

  id                    text
1  4      """my text here"""
2  2 """another text here"""

推荐阅读