comparing column headers from multiple sheets in an excel file and importing it to r

I don’t think you need to create an empty dataframe to compare all the columns. Try this approach :

library(readxl)
result <- purrr::map_df(months, ~read_excel("G:/Confidental.xlsx",sheet = .x), 
                       .id = 'months')

This would combine in all the sheets on one dataframe. If some of the column are absent in the sheet this will automatically insert NA for those columns in those month.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top