--Hello,
i try to merge excel sheets from a workbook into a dataframe, this is the code i use:
library(dplyr)
library("readxl")
library("purrr")
k <- map(1:4, # 4 sheets with the same first column 'targets'
~ read_excel("workbook.xlsx",
sheet = .x)) %>%
reduce(left_join, by = "targets")
df <- as.data.frame(k)
i works fine, but the column headers don't match the sheet names. How can I do this automatically?
i know i can do it manually like that:
sfx <- c("targets", "df1", "df2")
setnames(df,sfx)
thank you --