Hello, folks. In this tutorial we are going to convert the case of the string in R. The R language offers functions such as tolower(), toupper(), and casefold() to convert the case of the given string from upper to lower or vice versa as well.
Let’s see how these functions work.
Table of Contents[ hide]
**tolower() = **The tolower() function is used to convert the string characters to the lower case.
**toupper() = **The toupper() function is used to convert the string characters to upper case.
casefold() = The casefold function is used to convert the string characters from lower to upper case and vice versa as well.
1
tolower``(x)
x = string or a character vector
1
toupper``(x)
x = string or a character vector
In this section, we are going to convert a string or a character vector to a lower case using tolower() function.
1
tolower``(``"WWW.JOURNALDEV.COM"``)
Output = “www.journaldev.com”
1
2
df<-``c``(``"HAVE A GOOD DAY"``)
tolower``(df)
Output = “have a good day”
The tolower() function will convert the case of the characters to lower as shown above.
Now, let’s convert the case of the characters present in a data set ‘state.division’.
Let’s see how tolower() function converts the case of the string to lower case.
1
tolower``(state.division)
In the above output you can see that all the strings present in the column species get converted into small letters or lower cases.
#string #programming #java