I am working on importing an Excel workbook that has multiple sheets. The columns' types in the sheets were set to 'General' in Excel by default, so I changed them manually in Excel from General-type to Text-type except for one column that was changed into Number-type because its head was zeros and when I import it in R, it is dropped automatically if it's character, text, or general.
The task at hand is to combine the sheets in one data frame, and here is the code I am working on:
library(tidyverse)
library(readxl)
library(purrr)
library(ggplot2)
library(dplyr)
CombineSheets <- function(excel_file_path){
df <- excel_file_path %>%
excel_sheets() %>% #creates a character vector of the sheets' names
set_names() %>% #sets the names of each element in the character vector to itself
map_dfr(.f = ~read_excel(path = excel_file_path, sheet = ..1), .id = "sheet")
return(df)}
CombineSheets("C:\\Users\\Batool\\Documents\\ExcelFiles\\ConfigList.xlsx")
However, I am getting the error below although I have both columns set to the same type (Text) in Excel. So where could the issue be?
I thought about using R to search for the column of the data type to be Number and change it after importing the data set. However, by the time I import the sheet, the column would have been dropped. Any ideas or solution, please?
Error message: Error: Can't combine LWFM_W$PGN <character> and LWFM_N$PGN <double>.