Rename Column in R: Quick Guide

To rename a column, you can use the colnames() function in R language. For example, if you want to change the column name “old_colname” to “new_colname” in the dataframe df, you can use the following code:

# 给某个列改名
colnames(df)[colnames(df) == "old_colname"] <- "new_colname"

With this code, you can rename the column named “old_colname” in the df dataframe to “new_colname”.

bannerAds