R rename singl edf column

To rename a single column in an R dataframe, you can use the rename() function from the dplyr package. Here are the steps to rename a single column in R:

  1. Install and load the dplyr package:
install.packages("dplyr")  # Install the package
library(dplyr)  # Load the package
  1. Create a dataframe or use an existing one:
df <- data.frame(col1 = c(1, 2, 3), col2 = c("A", "B", "C"))  # Example dataframe
  1. Use the rename() function to rename the column:
df <- rename(df, new_col = col1)

In this example, the column named "col1" is renamed to "new_col".

  1. View the updated dataframe:
print(df)

The output will show the updated dataframe with the renamed column.

That's it! You have successfully renamed a single column in R using the rename() function from the dplyr package.