对不起,我的问题不清楚,所以改变了一下这个问题。
我正在用R预处理专利信息的数据。部分数据包括申请人或公司名称如下:
head(patent$applicant)
[1] Flextronics AP, LLC Flextronics AP, LLC Flextronics AP, LLC
[4] General Electric Company
如何在R的每一行的开头和结尾插入双引号?我想要的结果如下:
head(patent$applicant)
[1] "Flextronics AP, LLC" "Flextronics AP, LLC" "Flextronics AP, LLC"
[4] "General Electric Company"
希望dput()帮助您理解我的问题
head(dput(patent$applicant))
.......
"Zonar Systems, Inc.", "ZONAR SYSTEMS, INC.", "Zoom Information Systems",
"Zoop Mobility Network Inc.", "Zynga Inc."), class = "factor")
[1] Flextronics AP, LLC Flextronics AP, LLC Flextronics AP, LLC
[4] General Electric Company GM Global Technology Operations LLC Digimarc Corporation
2994 Levels: @Road, Inc. 1st Communications Inc. 2089275 ONTARIO LTD. ... Zynga Inc.
和str()一样。
str(patent$applicant)
Factor w/ 2994 levels "","@Road, Inc.",..: 864 864 864 956 1007 667 1512 2510 1671 1671 ...
我尝试过paste0()。结果如下:
head(paste0('"', patent$applicant, '"'))
[1] "\"Flextronics AP, LLC\"" "\"Flextronics AP, LLC\""
[3] "\"Flextronics AP, LLC\"" "\"General Electric Company\""
[5] "\"GM Global Technology Operations LLC\"" "\"Digimarc Corporation\""
感谢您的评论。它真的帮助了我。 我用单引号而不是双引号做到了。
> head(paste0("\'",patent$applicant,"\'"))
[1] "'Flextronics AP, LLC'" "'Flextronics AP, LLC'"
[3] "'Flextronics AP, LLC'" "'General Electric Company'"
[5] "'GM Global Technology Operations LLC'" "'Digimarc Corporation'"
答案 0 :(得分:-3)
如果数据是字符串格式,您可以使用paste()
函数来显示前导和尾随双引号。