I have 7 dataframes where the first variable is just a list of the 50 states. The problem is that in some of them, the states are all capitals, all lower case or mixed. Instead of writing 7 different tolower() commands, I was wondering if there is a way to do this using a loop or lapply()?
I've tried these two ways and neither worked:
ivs <- c("taxes","urban","gini","educ","inc","cong"))## a character vector of the data frame names
for (i in length(1:ivs)){
i$state <- tolower(i$state)
}
and this way:
ivs <- c("taxes","urban","gini","educ","inc","cong"))
sapply(ivs, function(x) {
x$state <- tolower(x$state)
})
Thanks for the help!