I have the following code in R that combines multiple (177) csv files. However in a lot of the files, some column names have spaces and the others have underscores as separators e.g ‘Article Number’ and ‘Article_Number’. I have tried janitor::make_clean_names and make.names etc within the code but I just cannot figure out the correct way to do it.
Any help much appreciated
df <- list_of_files %>%
set_names() %>%
map_dfr(
~read_csv(.x, col_types = cols(.default = "c", 'TY Stock Value' = "c"), col_names = TRUE,),
.id = "file_name"
)
>Solution :
You can add it insight the map_dfr function such that each columns get first harmoized before it gets bind together.
df <- list_of_files %>%
set_names() %>%
map_dfr(~ .x %>%
read_csv(.,
col_types = cols(.default = "c", "TY Stock Value" = "c"),
col_names = TRUE
)
%>%
janitor::clean_names(),
.id = "file_name"
)