I have previously used a function similar to this question/answer to read in multiple sheets and create a new id
variable based on the sheet name:
Importing and Renaming multiple sheets in a excel worksbook with map_df and read_excel
file_name <- "example.xlsx"
sheets <- readxl::excel_sheets(file_name)
data <- map_df(sheets, ~mutate(read_excel(file_name, sheet = .x),
id = .x))
However, I would now like to introduce additional steps to each sheet before joining sheets into a data frame. I would like to remove a row, transpose the sheet, and as the original column names in the excel files are times, create a new time variable. I can manage this with one sheet e.g.
time <-seq(ymd_hm('2023-04-20 12:00'),ymd_hm('2023-04- 11:50'),
by = '10 mins')
file_name <- "example.xlsx"
data <- readxl::read_excel(file_name)%>%
dplyr::slice(-3)%>%
sjmisc::rotate_df(cn = T) %>%
tibble()%>%
mutate(time = time))
I have not been able to successfully combine the steps, i.e. import, transpose/format sheets, create id variable based on sheet name, and combine all sheets in a data frame. I would appreciate a tidyverse based solution/advise, and apologise for the lack of a reproducible example, as not sure how to do this when the question regards reading in data.