Rename multiple column at once using rename() function
We can rename multiple columns at once using a vector that is by passing columns to vector.
Syntax:
rename(dataframe,c(newcolumn1=oldcolumn1,newcolumn2=oldcolumn2…,,newcolumn n=oldcolumn n))
Example: R program to rename multiple columns at once
R
# load the library library (dplyr) # create dataframe with 3 columns id,name # and address data1= data.frame (id= c (1,2,3,4,5,6,7,1,4,2), name= c ( 'sravan' , 'ojaswi' , 'bobby' , 'gnanesh' , 'rohith' , 'pinkey' , 'dhanush' , 'sravan' , 'gnanesh' , 'ojaswi' ), address= c ( 'hyd' , 'hyd' , 'ponnur' , 'tenali' , 'vijayawada' , 'vijayawada' , 'guntur' , 'hyd' , 'tenali' , 'hyd' )) # rename multiple columns # name with first_name # id with roll_no # address with street rename (data1, c (first_name=name,roll_no=id,street=address)) |
Output:
Rename the column name in R using Dplyr
In this article, we are going to rename the column name using dplyr package in the R programming language.
Dataset in use: