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]

Functions used for case conversion in R

**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.


Let’s start with the syntax

  • The syntax of the function tolower() is,

1

tolower``(x)    

x = string or a character vector

  • The syntax of the** toupper()** function is,

1

toupper``(x)

x = string or a character vector


Convert a string to lower case using tolower() function

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’.

Lower In R

Let’s see how tolower() function converts the case of the string to lower case.

1

tolower``(state.division)

Lower

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

How to convert the case of a string in R?
1.20 GEEK