Was it helpful?

Question

How to change the column names and row names of a data frame in R?

R ProgrammingServer Side ProgrammingProgramming

We can colnames function to change the column names and rownames function to change the row names.

Example

> df <- data.frame(ID=1:5,Salry=c(10000,30000,22000,27000,18000))
> df
ID Salry
1 1 10000
2 2 30000
3 3 22000
4 4 27000
5 5 18000
> colnames(df)<-c("EmployeeID","Salary")
> df
EmployeeID Salary
1 1 10000
2 2 30000
3 3 22000
4 4 27000
5 5 18000
> rownames(df)<-c("001","025","019","102","089")
df
EmployeeID Salary
001 1 10000
025 2 30000
019 3 22000
102 4 27000
089 5 18000
raja
Published on 06-Jul-2020 16:25:50
Advertisements
Was it helpful?
Not affiliated with Tutorialspoint
scroll top