Skip to content

Instantly share code, notes, and snippets.

@eddjberry
Last active February 19, 2019 11:56
Show Gist options
  • Save eddjberry/a2caedcab72c4e6a587fdea8cca93eff to your computer and use it in GitHub Desktop.
Save eddjberry/a2caedcab72c4e6a587fdea8cca93eff to your computer and use it in GitHub Desktop.
Format a string such that the first character is upper case and the rest are lower case
# a function to format strings
# to be in Proper case
str_proper <- function(string) {
# get the first letter
first_letter = substring(string, first = 1, last = 1)
# get the other letters
other_letters = substring(string, first = 2)
# combine the first letter (upper case)
# with the other leters (lower case)
paste0(toupper(first_letter),
tolower(other_letters))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment