- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to change the column names and row names of a data frame in R?
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
- Related Articles
- How to convert a matrix into a data frame with column names and row names as variables in R?
- How to convert a matrix to a data frame with column names and row names as new columns in R?
- How to sort an R data frame column without losing row names?
- How to change the repeated row names and column names to a sequence in a matrix in R?
- Find the column and row names in the R data frame based on condition.
- How to find the column names and row names from a matrix in R?
- How to remove column names from an R data frame?
- How to remove the row names or column names from a matrix in R?
- How to remove rows in an R data frame using row names?
- How to remove underscore from column names of an R data frame?
- How to convert a row into column names in R?
- How to create a subset of a data frame in R without using column names?
- How to deal with missing column for row names when converting data frame to data.table object in R?
- How to remove a common suffix from column names in an R data frame?
- Check which column names contain a specific string in R data frame.

Advertisements