Skip to content

Instantly share code, notes, and snippets.

@arcaravaggi
Last active November 13, 2017 11:48
Show Gist options
  • Select an option

  • Save arcaravaggi/e8c2a720dea43ab5d3f24e0fe5da0476 to your computer and use it in GitHub Desktop.

Select an option

Save arcaravaggi/e8c2a720dea43ab5d3f24e0fe5da0476 to your computer and use it in GitHub Desktop.
Capitalise the first letter of each word in a string
# 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