Modify Data Frames Using R

We need to continually alter the characteristics of rows and columns during the data-wrangling process to enable easier formatting and optimization for subsequent steps. Below are some of the most commonly employed methods in data analysis.

Modify column names

The colnames() command lists the column names. This command returns the column names as vectors of string values. Column names can be altered by assigning new values to the output of the colnames() command.

Note: The number of new column names and the columns must be equal. Otherwise, the columns without labels are automatically represented as NA.

Get hands-on with 1200+ tech skills courses.