Learn R Programming

SGP (version 1.0-3.0)

capwords: Function for converting all caps to mixed case. Useful in data cleaning.

Description

The function capwords converts characters to mixed case character as intelligently as possible.

Usage

capwords(x,
	 special.words = c("ELA", "II", "III", "IV", "EMH", "HS", "MS", "ES", "SES", "IEP", "ELL", "MAD", "SD", "US", "SGP"))

Arguments

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.

Value

  • Returns a mixed case character string.

Examples

Run this code
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)

Run the code above in your browser using DataLab