Learn R Programming

R.utils (version 2.9.0)

capitalize: Capitalizes/decapitalizes each character string in a vector

Description

Capitalizes/decapitalized (making the first letter upper/lower case) of each character string in a vector.

Usage

# S3 method for default
capitalize(str, ...)
  # S3 method for default
decapitalize(str, ...)

Arguments

str

A vector of character strings to be capitalized.

...

Not used.

Value

Returns a vector of character strings of the same length as the input vector.

See Also

toCamelCase.

Examples

Run this code
# NOT RUN {
words <- strsplit("Hello wOrld", " ")[[1]]
cat(paste(toupper(words), collapse=" "), "\n")      # "HELLO WORLD"
cat(paste(tolower(words), collapse=" "), "\n")      # "hello world"
cat(paste(capitalize(words), collapse=" "), "\n")   # "Hello WOrld"
cat(paste(decapitalize(words), collapse=" "), "\n") # "hello wOrld"

# Sanity checks
stopifnot(paste(toupper(words), collapse=" ") == "HELLO WORLD")
stopifnot(paste(tolower(words), collapse=" ") == "hello world")
stopifnot(paste(capitalize(words), collapse=" ") == "Hello WOrld")
stopifnot(paste(decapitalize(words), collapse=" ") == "hello wOrld")
# }

Run the code above in your browser using DataLab