rename column with a variable in r code example
Example 1: how to change column names in r
colnames(dataset) <- c('name1','name2',..)
Example 2: R rename singl edf column
colnames(trSamp)[2] <- "newname2"
Example 3: rename column in r
my_data %>%
rename(
sepal_length = Sepal.Length,
sepal_width = Sepal.Width
)
Example 4: r rename column based on variable
df %>% rename(!!variable := name_of_col_from_df)