Convert to Title case in R dataframe column

To convert a column in R to title case we use str_to_title() function of “stringr” package. Let’s see how to convert to title case or proper case in R with an example.

Let’s first create the dataframe.

df1 = data.frame(State = c('Arizona AZ','Georgia GG', 'Newyork NY','Indiana IN','Florida FL'), 
                 Score=c(62,47,55,74,31))
df1

So the dataframe will be

Convert to title case in R dataframe column 1

 

Convert to title case or proper case in R dataframe:

str_to_title() function of “stringr” package is used to convert the column to title case or proper case in R.

library(stringr)
df1$state_title_case = str_to_title(df1$State)
df1

So the title case converted column along with dataframe will be

Convert to title case in R dataframe column 2

Convert to Title case in R dataframe column - image previous-small-11-1 on http://www.datasciencemadesimple.com                                                                                                      Convert to Title case in R dataframe column - image next_small-11-1 on http://www.datasciencemadesimple.com