R.Kim
R.Kim

Reputation: 587

How do I change all column names to the first row of that column in R?

Column names in dataset are unrecognizable values. But, the name of what the column should be is the 1st row. How can I re-assign those values as the column name? This needs to be done with 30+ columns. Here's a screenshot of the dataset:

enter image description here

Upvotes: 0

Views: 1915

Answers (1)

Pdubbs
Pdubbs

Reputation: 1987

Simple: colnames(dataset) <- dataset[1,]

Although really you should be reading in the column names when you read the dataset with header=T in whatever your read function of choice is. This will have the added benefit of letting your columns be their actual datatypes, as with the header row now they're all going to be strings.

Upvotes: 2

Related Questions