Skip to Content

Convert String to Uppercase in R

When working with strings in R, it can be handy to know how to quickly change its case. In this tutorial, we will look at how to convert the case of a string to uppercase in R with the help of some examples.

How do I convert a string to uppercase in R?

convert string to uppercase in R

You can use the built-in toupper() function to convert a string to uppercase in R. Pass the string you want to convert as an argument to the toupper() function.

The following is the syntax –

# string s to uppercase

It returns the passed string as an uppercase string.

You can also apply this function to a vector of strings to convert each string in the vector to uppercase.

Highlighted programs for you

Flatiron School

Flatiron School

Data Science Bootcamp
Product Design UX/UI Bootcamp

University of Maryland Global Campus

University of Maryland Global Campus

Cloud Computing Systems Master's
Digital Forensics & Cyber Investigation Master's

Creighton University

Creighton University

Health Informatics Master's

Let’s now look at some examples of using the toupper() function.

Convert string to uppercase

Here, we will create a string with characters having mixed cases. That is some characters will be uppercase and some lowercase. We’ll then pass the string to the toupper() function.

# create a string
s <- "pLeAsE dO nOt tYPe lIkE THiS"
# convert string to uppercase



You can see that all the characters in the returned string are in uppercase.

Convert a vector of strings to uppercase

You can also apply the toupper() function to a vector of strings.

Let’s look at an example.

Here, we will create a vector of some string values and then apply the toupper() function on the vector itself.

# create a vector of strings
vec <- c("HELLO", "Howdy", "hoLA", "namaste")
# convert vector to uppercase


[1] "HELLO"   "HOWDY"   "HOLA"    "NAMASTE"

You can see that each string in the resulting vector is in uppercase.

You might also be interested in –

Subscribe to our newsletter for more informative guides and tutorials.
We do not spam and you can opt out any time.


  • Piyush Raj

    Piyush is a data professional passionate about using data to understand things better and make informed decisions. He has experience working as a Data Scientist in the consulting domain and holds an engineering degree from IIT Roorkee. His hobbies include watching cricket, reading, and working on side projects.