tolower()

tolower(x)
Returns: character · Updated March 13, 2026 · String Functions
strings case text base

tolower() converts character vectors to lowercase. This function is essential for case-normalization when comparing strings, cleaning user input, and standardising text data for analysis or storage.

Syntax

tolower(x)

Parameters

ParameterTypeDefaultDescription
xcharacterA character vector to convert

Examples

Basic usage

tolower("HELLO WORLD")
# [1] "hello world"

tolower("HeLLo WoRLd")
# [1] "hello world"

Working with vectors

fruits <- c("Apple", "BANANA", "Cherry")
tolower(fruits)
# [1] "apple"  "banana" "cherry"

Practical applications

# Case-insensitive matching
names <- c("Alice", "BOB", "charlie")
target <- "alice"

tolower(names) == tolower(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 <- tolower(raw_data$name)
raw_data$city <- tolower(raw_data$city)

# Result: all lowercase
#       name     city
# 1    alice  new york
# 2      bob    london
# 3  charlie     paris

Normalize categorical data

responses <- c("Yes", "YES", "yes", "y", "Y")
unique(tolower(responses))
# [1] "yes" "y"

See Also