how to remove space from column names of multiple data frames without merging the data frames in rbc?

Anonymous functions in lapply need to take an argument (and the return() needs to be inside the function). Can’t test without a reproducible example, but I would guess this will work:

dfs <- Filter(function(x) is(x, "data.frame"), mget(ls()))
lapply(dfs, function(x) {
  names(x) = names(x) %>% 
    stringr::str_remove_all("-") %>%
    str_replace_all( "\\s+", "_" ) %>%  ## added the + just in case
    tolower
  return(x)
})

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top