Last active
February 19, 2019 11:56
-
-
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
This file contains 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
# 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