How to convert characters from upper to lower case in R?

[This article was first published on Data Science Tutorials, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The post How to convert characters from upper to lower case in R? appeared first on Data Science Tutorials

How to convert characters from upper to lower case in R?. This article discusses how to change a character’s case in R from upper to lower and vice versa.

Will include examples for the R methods tolower(), toupper(), casefold(), and chartr() throughout the lesson.

How to convert characters from upper to lower case or vice versa in R?

We must first generate a character string in R before proceeding to the examples. We’ll use the character string “Datasciencetut.com” throughout this tutorial:

Let’s create an example character string

string<- "Datasciencetut.com"
string
[1] "Datasciencetut.com"

Example 1: tolower & toupper R Functions

Will describe how to utilize the tolower and toupper R functions in the first example.

Statistical test assumptions and requirements – Data Science Tutorials

With the tolower command, we may change every character in our string to lower case:

tolower(string)                          
[1] "datasciencetut.com"

Contrarily, the toupper command is used to change every character to upper case.

toupper(string)                               
[1] "DATASCIENCETUT.COM"

Example 2: casefold Function

The translation to tiny or uppercase letters is also possible with the casefold R function.

If we use the casefold function with the upper = FALSE (default option) argument, our characters are changed to lower case.

casefold(string, upper = FALSE)            
[1] "datasciencetut.com"

…or to upper case if we specify upper = TRUE:

casefold(string, upper = TRUE)                
[1] "DATASCIENCETUT.COM"

In actuality, the casefold function is identical to the tolower and toupper functions.

Best Books to learn Tensorflow – Data Science Tutorials

Example 3: chartr Function

An whole character string can be converted to lowercase or uppercase using the tolower, toupper, and casefold methods.

The chartr function can be used to convert some characters to lower case and others to upper case:

chartr(old = "Datasciencetut.com", new = "DataScienceTut.COM", string)    
[1] "DataSCienCetut.COM"

A new character pattern or an old character pattern can both be specified using the chartr function. The previous pattern is subsequently replaced by the new one.

One way ANOVA Example in R-Quick Guide – Data Science Tutorials

The post How to convert characters from upper to lower case in R? appeared first on Data Science Tutorials

To leave a comment for the author, please follow the link and comment on their blog: Data Science Tutorials.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)