← Back to R Course | Chapter 6: Strings | Lesson 4 of 7

toupper and tolower

In this page:

  1. toupper and tolower

toupper and tolower

toupper() converts a string to all uppercase, and tolower() converts it to all lowercase. Both work element-wise across a vector of strings. They're commonly used for case-insensitive comparisons by normalizing both sides to the same case first.

Note: For case-insensitive comparisons, normalize both strings with tolower() before comparing them with ==.

Example: toupper and tolower

markup
text <- "Hello World"

cat(toupper(text), "\n")
cat(tolower(text), "\n")
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.