r 从特定 sheet 批量读取 xls 文件
r batch reading xls files from specific sheet
我的文件夹中有大约 30 个 excel 个文件。
我有兴趣全部看完。
我在下面使用了这段代码
library(readxl)
file.list <- list.files(pattern='*.xlsx')
df.list <- lapply(file.list, read_excel)
问题是每个 excel 文件都有多个 sheet,而我只对一个 sheet 的内容感兴趣,sheetName = "Piano", 对其他 sheets.
的内容不感兴趣
那么我如何确保除了读取所有 30 个 excel 文件之外,r 只从所有这些 excel 文件中读取来自 sheetName="Piano" 的数据.谢谢
我们可以利用 read_excel
的 sheet
参数。根据?read_excel
sheet - Sheet to read. Either a string (the name of a sheet), or an integer (the position of the sheet). Ignored if the sheet is specified via range. If neither argument specifies the sheet, defaults to the first sheet.
library(dplyr)
library(readxl)
df.list <- map(file.list, read_excel, sheet = 'Piano')
我的文件夹中有大约 30 个 excel 个文件。
我有兴趣全部看完。
我在下面使用了这段代码
library(readxl)
file.list <- list.files(pattern='*.xlsx')
df.list <- lapply(file.list, read_excel)
问题是每个 excel 文件都有多个 sheet,而我只对一个 sheet 的内容感兴趣,sheetName = "Piano", 对其他 sheets.
的内容不感兴趣那么我如何确保除了读取所有 30 个 excel 文件之外,r 只从所有这些 excel 文件中读取来自 sheetName="Piano" 的数据.谢谢
我们可以利用 read_excel
的 sheet
参数。根据?read_excel
sheet - Sheet to read. Either a string (the name of a sheet), or an integer (the position of the sheet). Ignored if the sheet is specified via range. If neither argument specifies the sheet, defaults to the first sheet.
library(dplyr)
library(readxl)
df.list <- map(file.list, read_excel, sheet = 'Piano')