r - convert names to character strings -


this question has answer here:

i came across meta-programming task seemed must have obvious , simple answer, not find one.

i have bunch of names wrapped in ():

(foo, bar, buzz, zap) 

i want convert these names character vector:

("foo", "bar", "buzz", "zap") 

the fastest come follows:

as.character(quote(c(foo, bar, buzz, zap)))[-1] # "foo"  "bar"  "buzz" "zap"  

i've got imagine there's cleaner solution.

edit

possible duplicate, different title hard discover: does r have quote-like operators perl's qw()?

a. option1

 k<-"(foo, bar, buzz, zap)"     strsplit(strsplit(k,"\\(|\\)")[[1]][2],", ")[[1]]     [1] "foo"  "bar"  "buzz" "zap"  

b. option 2

library(stringr) str_extract_all(k,"[aa-zz]+")[[1]] #assuming contains letters [1] "foo"  "bar"  "buzz" "zap" 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -