I have a bunch of data sets for which I would like to apply a renaming function to all of the columns. I have built the function and got to the point where I have a list of data frames with renamed columns but I am stuck on how to reassign these data frames back to the original ones. Could someone help me on this last step or advise on a simpler way of doing this?
A = data.frame(Var 1 = c(1,2,3,4), Var 2 = c(1,2,3,4))
B = data.frame(Var 3 = c(1,3,4,7), Var 4 = c(1,2,3,4))
better_names <- function(x) {
names(x) <- names(x) %>% stringr::str_replace_all("\\s","_") %>% tolower
return(x)
}
list_data <- list(A, B)
l <- lapply(list_data, better_names)