Deleting first few rows and change the header names to row values

Viewed 8200

I have a data frame which has column names assigned by R.

Col1   Col2   Col3
NA     NA     ABC
NA     NA     XYZ
Name1  Name2  Name3
Joe    Paul   Ross

I want to delete the first 3 rows including the Col Numbers header assigned by R, and Make Name1, Name2, Name 3 the header names of the columns in the dataframe.

to delete the rows, I was trying to do tail(df,-3).. But it's not removing Col Number rows, and deleting my Name row

1 Answers

You need

names(df) <- df[3,]

then

df <- df[-c(1:3),]

df
  Name1 Name2 Name3
4   Joe  Paul  Ross
Related