How to use rename_with() In R Language
rename_with() is used to change the case of the column.
- uppercase: To convert to uppercase, the name of the dataframe along with the toupper is passed to the function which tells the function to convert the case to upper.
Syntax:
rename_with(dataframe,toupper)
Where, dataframe is the input dataframe and toupper is a keyword that converts all columns to upper
- lowercase: To convert to lowercase, the name of the dataframe along with the tolower is passed to the function which tells the function to convert the case to lower.
Syntax:
rename_with(dataframe,tolower)
where dataframe is the input dataframe and tolower is a keyword that converts all columns to lower.
Example: R program to convert columns to upper and lower
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' )) # convert all columns to upper rename_with (data1,toupper) print ( "==============" ) # convert all columns to lower rename_with (data1,tolower) |
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: