add quotation mark to a vector in R [duplicate]

2020-06-16 05:50发布

Just wonder if there is any shortcut in R to add the quotation mark to a vector? So it will be like c(lemon, orange, apple) to c("lemon", "orange", "apple") without manually going to each item to change it since sometimes many items can be in a vector. Thanks.

标签: r
2条回答
狗以群分
2楼-- · 2020-06-16 06:09

You can try

 as.character(quote(c(lemon, orange, apple)))[-1]

Or another option as suggested by @MrFlick in the comments

 as.character(expression(lemon, orange, apple))
查看更多
走好不送
3楼-- · 2020-06-16 06:13
v = c("lemon", "orange", "apple")
v = paste0('"', v, '"')
# use cat in this case to see what's "really" there
# print will show the quotes escaped with backslashes
cat(v)
## "lemon" "orange" "apple"
查看更多
登录 后发表回答