import excel dataset with several sheets into R

Hi,

I need to import an Excel dataset with 4 sheets into R. I started with these codes but I'm stuck in the next step, importing the dataset into R.
This is what I used so far:

sheet_names <- excel_sheets("Alldata\Alldata_v20230616.xlsx") #get sheet names
sheet_names #print sheet names

Alldata_sheets <- lapply(sheet_names, function(x)

  • {as.data.frame(read_excel("Alldata\Alldata_v20230616.xlsx", sheet = x))}) #Read all sheets to list
    names(Alldata_sheets) <- sheet_names #rename list elements

head(Alldata_sheets$sheet1) # print head of sheet1
head(Alldata_sheets$sheet2) # print head of sheet2
head(Alldata_sheets$sheet3) # print head of sheet3
head(Alldata_sheets$sheet4) # print head of sheet4

My question is how to proceed and import data foe all sheets into R?

Thank you

It seems you already have the data in a list in R. Do you mean that you want to have the data from each sheet in separate data frames? To make data frames with the same names as your sheets, try

for(Nm in sheet_names) {
  assign(Nm, Alldata_sheets[[Nm]])
}

Thank you. I got the data I needed

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.