David Edwards
David Edwards

Reputation: 33

Vector of column names

I have a data set. Data1

    Type    x1        x2      x3  ...
1:  type1   1.54    1.48    1.88    
2:  type2   1.46    1.99    1.48
3:  type1   2.01    1.02    1.03
...

I want to create a vector, x, of the column names excluding the first column. It is surely simple, I am a novice.

Upvotes: 0

Views: 1119

Answers (1)

jsavn
jsavn

Reputation: 805

As suggested by user Matthew Farant, the function names() gives you the column names of a data.frame, e.g. names(Data1).

To get the names excluding the first column, you can either subset the vector of names, e.g. names(Data1)[-1], or you can subset the data, and get the names of the subset of data excluding the first column, names(Data1[,-1].

In case your data is a matrix, you can use the colnames() function instead.

Upvotes: 1

Related Questions