怎么把同一excel中不同Sheet的数据提取到一起?
问题描述:这一个excel中共有32个Sheet,我要将每个sheet中的几列提取出来到一个新的excel中。
library(readxl)
library(data.table)
library(writexl)
rm(list = ls())
file_path <- "Data File.xlsx"
sheet_names <- excel_sheets(file_path)
combined_df <- data.frame(matrix(numeric(0), nrow = 0, ncol = 5))
for(sheet in sheet_names) {
temp_df <- read_excel(file_path, sheet = sheet)
temp_df = temp_df[12:16]
combined_df <- rbind(combined_df, temp_df)
cat("Sheet:", sheet, "- Rows:", nrow(temp_df), "\n")
}
write_xlsx(combined_df,"E:\\1_Research\\8_Erhai\\3_Data\\3_我整理\\Site2data.xlsx")