Just accesses editing.
@nzcoops, you don't need the column names in the comma delimited character. You think about it wrong. When you do
vec <- c("col1", "col2", "col3")
you create a symbol vector. , simply separates the arguments used by c() when defining this vector. names() and similar functions return a character vector of names.
> dat <- data.frame(col1 = 1:3, col2 = 1:3, col3 = 1:3) > dat col1 col2 col3 1 1 1 1 2 2 2 2 3 3 3 3 > names(dat) [1] "col1" "col2" "col3"
It is much easier and fewer errors to select from names(dat) elements than to process its output in a comma-separated string that you can cut and paste.
Let's say we need the col1 and col2 , a subset of names(dat) that only keep the ones we want:
> names(dat)[c(1,3)] [1] "col1" "col3" > dat[, names(dat)[c(1,3)]] col1 col3 1 1 1 2 2 2 3 3 3
You can do what you want, but R will always print the vector on the screen in quotation marks " :
> paste('"', names(dat), '"', sep = "", collapse = ", ") [1] "\"col1\", \"col2\", \"col3\"" > paste("'", names(dat), "'", sep = "", collapse = ", ") [1] "'col1', 'col2', 'col3'"
therefore, the latter may be more useful. However, now you need to cut and go from this line. It is much better to work with objects that return what you want and use standard subsets of routines to save what you need.