I want to change few specific column names of a data frame using dplyr's pipe. Below is one such example -
library(dplyr)
head(mtcars)
Now let say, I want to change 2nd and 3rd column names to "a"
and "b"
respectively. Trivially, I could do it as
colnames(mtcars)[2] <- "a"
colnames(mtcars)[3] <- "b"
However I want to do it using pipe
and in a single line to enhance readability.
Any suggestion how should I do it?
Many thanks for your time.