Function for converting all caps to mixed case. Useful in data cleaning.
The function capwords converts characters to mixed case character as intelligently as possible and leading/trailing spaces.
capwords(x, special.words = c("ELA","I", "II", "III", "IV", "EMH", "HS", "MS", "ES", "SES", "IEP", "ELL", "MAD", "PARCC", "SBAC", "SD", "SWD", "US", "SGP", "SIMEX", "SS", "SAT", "PSAT"))
x |
A character string to be converted to mixed case. |
special.words |
A character vector (see default above), specifying words to not convert to mixed case. |
Returns a mixed case character string.
Damian W. Betebenner dbetebenner@nciea.org
capwords("TEST") ## Test capwords("TEST1 TEST2") ## Test1 Test2 capwords("O'NEIL") ## O'Neil capwords("JOHN'S") ## John's ## Use sapply for converting character vectors test.vector <- paste("TEST", 1:10, sep="") sapply(test.vector, capwords) ## With factors, convert levels instead of the entire vector test.factor <- factor(paste("TEST", rep(letters[1:10], each=50))) levels(test.factor) <- sapply(levels(test.factor), capwords) levels(test.factor)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.