Basically I am having different sheets from excel file and I want to import each and every sheet to RStudio and to add the sheet name in every data frame as a variable, as I want to make one data frame but I need to know from which sheet they are from?
library(readxl)
read_excel_allsheets <- function("datafile", tibble = false) {
sheets <- readxl::excel_sheets("datafile")
x <- lapply(sheets, function(X) readxl::read_excel("datafile", sheet = X))
if(!tibble) x <- lapply(x, as.data.frame)
names(x) <- sheets
x
}
#Integra las hojas en una sola
datos = x[[1]]
for(i in 2:3){
datoscompletos = rbind.data.frame(datos,x[[i]])
datos = datoscompletos
}