r – Change letter case of column names

r – Change letter case of column names

Here is a one-liner implementing the easiest way to match column names among data sets that I can think of:

## Columns 1:3 left unaltered since they are not place names.
names(my.data2)[-1:-3] <- tolower(names(my.data2)[-1:-3])

## View the results
names(my.data2)
# [1] landuse       units         grade         clay         
# [5] lincoln       basinandrange mccartney     maple   

Easy Solution

names(DF) <- toupper(names(DF))

r – Change letter case of column names

modern solution

This is now a job for janitor::clean_names(), just choose case parameter that fits you need.

Leave a Reply

Your email address will not be published.