我正在阅读一个 excel 工作簿,其中包含从 2017 年 12 月到 2019 年 9 月的数据表。我已经导入了包含所有工作簿的电子表格,并希望转置所有工作表并将所有行绑定到一个数据集中。
下面是我的代码。
names(SheetList)
> [1] "Dec. 17" "Jan. 18" "Feb. 18" "March 18" "April 18" "May
> 18" "June 18" "July 18" "Aug. 18 "
> [10] "Sept. 18" "Oct. 18"
> "Dec.18" "Jan-19" "Feb-19" "Mar-19" "Apr-19" "May-19"
> "June-19"
> [19] "July-19" "August-19" "Sept.-19"
df <- data.frame()
for (sheet in names(SheetList)){
df <- Sheetlist[[sheet]] %>%
t() %>%
rbind.data.frame(df, .)
}
假设工作表列表是数据帧的列表。
转置然后行绑定:
result <- do.call(rbind, lapply(SheetList, t))