Last active
November 13, 2017 11:48
-
-
Save arcaravaggi/e8c2a720dea43ab5d3f24e0fe5da0476 to your computer and use it in GitHub Desktop.
Capitalise the first letter of each word in a string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Capitalise the first letter of each word in a string | |
| # From https://stackoverflow.com/questions/6364783/capitalize-the-first-letter-of-both-words-in-a-two-word-string | |
| # | |
| # e.g. | |
| # name <- c("great shearwater", "black-browed albatross", "southern giant petrel") | |
| # sapply(name, simpleCap) | |
| simpleCap <- function(x) { | |
| s <- strsplit(x, " ")[[1]] | |
| paste(toupper(substring(s, 1,1)), substring(s, 2), | |
| sep="", collapse=" ") | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment