toupper()
toupper(x) Returns:
character · Updated March 13, 2026 · String Functions strings case text base
toupper() converts character vectors to uppercase. This function is essential for case-normalization when comparing strings, cleaning user input, and standardising text data for analysis or storage.
Syntax
toupper(x)
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
x | character | — | A character vector to convert |
Examples
Basic usage
toupper("hello world")
# [1] "HELLO WORLD"
toupper("HeLLo WoRLd")
# [1] "HELLO WORLD"
Working with vectors
fruits <- c("Apple", "BANANA", "Cherry")
toupper(fruits)
# [1] "APPLE" "BANANA" "CHERRY"
Practical applications
# Case-insensitive matching
names <- c("Alice", "BOB", "charlie")
target <- "ALICE"
toupper(names) == toupper(target)
# [1] TRUE FALSE FALSE
Common Patterns
Case-insensitive table lookup
lookup_table <- c("yes" = 1, "no" = 2, "maybe" = 3)
user_response <- "YES"
lookup_table[toupper(user_response)]
# YES
# 1
Data cleaning pipeline
raw_data <- data.frame(
name = c("ALICE", "bob", "Charlie"),
city = c("new york", "London", "PARIS")
)
raw_data$name <- toupper(raw_data$name)
raw_data$city <- toupper(raw_data$city)
# Result: all uppercase
# name city
# 1 ALICE NEW YORK
# 2 bob LONDON
# 3 CHARLIE PARIS