capwords(x, special.words = c("ELA","I", "II", "III", "IV", "CCSD", "CUSD", "CUD", "USD", "PSD", "UD", "ESD", "DCYF", "EMH", "HS", "MS", "ES", "SES", "IEP", "ELL", "MAD", "PARCC", "SBAC", "SD", "SWD", "US", "SGP", "SIMEX", "SS", "SAT", "PSAT", "WIDA", "ACCESS", "WIDA-ACCESS"))
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.
capwords("TEST") ## Test#> [1] "Test"capwords("TEST1 TEST2") ## Test1 Test2#> [1] "TEST1 TEST2"capwords("O'NEIL") ## O'Neil#> [1] "O'Neil"capwords("JOHN'S") ## John's#> [1] "John's"## Use sapply for converting character vectors test.vector <- paste("TEST", 1:10, sep="") sapply(test.vector, capwords)#> TEST1 TEST2 TEST3 TEST4 TEST5 TEST6 TEST7 TEST8 #> "TEST1" "TEST2" "TEST3" "TEST4" "TEST5" "TEST6" "TEST7" "TEST8" #> TEST9 TEST10 #> "TEST9" "TEST10"## 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)#> [1] "Test A" "Test B" "Test C" "Test D" "Test E" "Test F" "Test G" "Test H" #> [9] "Test I" "Test J"