In this tutorial, we will learn how to change column name of R Dataframe.

Column names of an R Dataframe can be acessed using the function colnames(). You can also access the individual column names using an index to the output of colnames() just like an array.

To change all the column names of an R Dataframe, use colnames() as shown in the following syntax

To change a single column name of an R Dataframe, use colnames() with index as shown in the following syntax

Example to change a single Column Name of Dataframe

In this example, we will create an R dataframe DF1 and change the second column’s name to “newC”.

The column name C2 has changed to newC.

Example to change all Column Names of Dataframe

In this example, we will create an R dataframe DF1 and change all the column’s names.

All the column names have been changed.