words <- strsplit("Hello wOrld", "")[[1]];
cat(paste(toupper(words), collapse=""), "") # "HELLO WORLD"
cat(paste(tolower(words), collapse=""), "") # "hello world"
cat(paste(capitalize(words), collapse=""), "") # "Hello WOrld"
cat(paste(decapitalize(words), collapse=""), "") # "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