R/capwords.R

Defines functions capwords

######################################################################################################################

# Function: capwords.
# Argument: String.
# Description: This function is used to capitalize every first letter of a word

capwords <- function(s, strict = FALSE) {
  cap <- function(s) paste(toupper(substring(s, 1, 1)),
                           {s <- substring(s, 2); if(strict) tolower(s) else s},
                           sep = "", collapse = " " )
  sapply(strsplit(s, split = " "), cap, USE.NAMES = !is.null(names(s)))
}
gpaux/Mediana documentation built on May 31, 2021, 1:22 a.m.