I'm trying to loop through several data frames that I import and convert all the variables to lowercase. I currently do it this way (I have about 20 data frames in my actual code):
datasets <- c("iris", "mtcars")
for (i in 1:length(datasets)) {
df <- as.data.frame(get(datasets[i]))
colnames(df) <- tolower(colnames(df))
assign(paste0(datasets[i]), df)
}
I've previously read that using get
and assign
are not best practice so I was wondering how I could do this differently.