The “rename” Function in R

  • Package: dplyr

  • Purpose: To rename columns in a data frame.

  • General Class: Data Manipulation

  • Required Argument(s):

    • data: A data frame.

    • ...: A set of column name pairs to rename, where the names on the right-hand side are the current names, and the names on the left-hand side are the new names.

  • Notable Optional Arguments:

    • None

  • Example:

  • # Example usage
    library(dplyr)

    # Create a sample data frame
    df <- data.frame(A = 1:3, B = c("foo", "bar", "baz"))

    # Rename columns in the data frame
    df_renamed <- df %>% rename(new_A = A, new_B = B)

    # Print the original and renamed data frames
    print(df)
    print(df_renamed)

  • In this example, the rename function from the dplyr package is used to rename columns in a data frame (df). The resulting data frame with renamed columns (df_renamed) is then printed for comparison.

Previous
Previous

The “str_glue” Function in R

Next
Next

The “readRDS” Function in R