Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add quotation mark to a vector in R [duplicate]

Tags:

r

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.

like image 994
kelvinfrog Avatar asked May 15 '15 15:05

kelvinfrog


2 Answers

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))
like image 94
akrun Avatar answered Oct 05 '22 15:10

akrun


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"
like image 42
Gregor Thomas Avatar answered Oct 05 '22 15:10

Gregor Thomas