0
votes

In R: Is there an automated way to get the colnames of a dataframe (for example: mtcars):


colnames(mtcars)

output: [1] "mpg" "cyl" "disp" "hp" "drat" "wt" "qsec" "vs" "am" "gear" "carb"


to a concatenated vector like this:


c("mpg", "cyl", "disp", "hp", "drat", "wt", "qsec", "vs", "am", "gear", "carb")

1
ok. so not a vector but in this form: c("mpg", "cyl", "disp", "hp", "drat", "wt", "qsec", "vs", "am", "gear", "carb").TarJae

1 Answers

1
votes

colnames(mtcars) is already a vector. The format that you have shown can be achieved with dput i.e

dput(colnames(mtcars))

c("mpg", "cyl", "disp", "hp", "drat", "wt", "qsec", "vs", "am", "gear", "carb")