从Excel工作簿的几张纸中选择基于列名的特定列
我有一个带有几张纸的Excel工作簿。每张纸代表一年,并包含几列。并非所有的床单都有相同的列名称,但是我想拿出具有所有床单中共享名称的特定列。
我使用以下功能导入表格将其纳入列表中,
sheets <- readxl::excel_sheets(filename)
x <- lapply(sheets, function(X) readxl::read_excel(filename, skip = 2, sheet = X))
if(!tibble) x <- lapply(x, as.data.frame)
names(x) <- sheets
x }
现在有一个包含大约7个元素的大列表。我创建了另一个列表,其中包含我想从每个表格中删除的列名
select&lt; -list(c(“平均”,“ total”,“ attry”,“百分比”,“年”))
>
我如何使用此列表将每个纸上的各个列将其拉出到新的DF中?
抱歉,如果相当明显,并提前感谢您的任何建议!
I've got an excel workbook with several sheets. Each sheet represents a year and contains several columns. Not all the sheets have the same columns names but I want to pull out specific columns with names that are shared in all sheets.
I've imported the sheet using the following function to make it into a list
sheets <- readxl::excel_sheets(filename)
x <- lapply(sheets, function(X) readxl::read_excel(filename, skip = 2, sheet = X))
if(!tibble) x <- lapply(x, as.data.frame)
names(x) <- sheets
x }
I now have a large list containing about 7 elements. I created another list containing the column names I want to pull out from each sheet
select <-list(c("average","total","percentage","year on year"))
How do I use this list to pull out the respective columns from each sheet into a new df?
Sorry if fairly obvious and thanks in advance for any advice!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们可以
选择
之后列。另外,只需传递vector
列名称We may
select
the columns afterwards. Also, instead oflist
of element 1, just pass avector
of column names