R. Ladwein
R. Ladwein

Reputation: 31

Get variables names from a data frame in a vector

I can obtain the names of my variables of a data frame with the command "names (df)". It gives say:

#[1] "V1"  "V2"  "V3"

But I would like to obtain a vector, something like this:

c("V1", "V2", "V3")

Is this possible in R?

Thanks in advance for your response

Richard

Upvotes: 1

Views: 1043

Answers (1)

Oka
Oka

Reputation: 1328

It is possible and you can just make a new vector with the names like this:

x <- names(df)

..and the names will be stored in vector x

Upvotes: 1

Related Questions