I was wondering why names()
or colnames()
return the names of at least 2 columns in the data.frame
in R?
For example, names(mtcars[, 2])
returns NULL
but names(mtcars[, 2:3])
, works perfectly ok (i.e., returns "cyl" "disp"
)?
What to do to get the name of a single column in a data.frame
, then?