What is casefold() Function in R

The casefold() is a built-in R function that is a generalized solution to convert to either lowercase or uppercase letters. It converts a character vector to upper or lower case, depending on the value of the parameter upper.

If you pass upper = FALSE, it will convert to lowercase letters; if you pass upper = TRUE, it will return the uppercase string.

Syntax

casefold(string, upper=F)

Parameters

  1. string: It is a string character or a character data frame.
  2. upper: It is a case that the string will be lower if mentioned FALSE and upper if mentioned TRUE.

Example

data <- "RICK AND MORTY ARE VINDICATORS"

converted <- casefold(data, upper = FALSE)

converted

Output

[1] "rick and morty are vindicators"

You can see from the output that we got the lowercase characters string.

If we pass the upper = TRUE, it will return the uppercase characters string.

Leave a Comment