如何将多个.xls文件(每个文件有多张工作表)导入R版本3.5.3?
我有27个xls文件要导入到R中,每个文件在工作簿中都有多张工作表。我试图一次上载所有文件,每个文件中只有第一张图纸被导入到自己的数据框中(此时不需要导入其他图纸) 我看到一些人创建了一个文件列表,然后使用readxl包,但是我使用的是最新版本的R(3.5.3),据我所知,它不兼容如何将多个.xls文件(每个文件有多张工作表)导入R版本3.5.3?,r,import,xls,R,Import,Xls,我有27个xls文件要导入到R中,每个文件在工作簿中都有多张工作表。我试图一次上载所有文件,每个文件中只有第一张图纸被导入到自己的数据框中(此时不需要导入其他图纸) 我看到一些人创建了一个文件列表,然后使用readxl包,但是我使用的是最新版本的R(3.5.3),据我所知,它不兼容 我希望最终得到27个单独的数据帧,然后我可以在其中添加一列来标识特定的数据帧,这样它们就可以组合到一个数据帧中使用。文件列表和readxl工作得很好。我已经用创建了3个excel文件 Mappe1.xlsx-表1-A
我希望最终得到27个单独的数据帧,然后我可以在其中添加一列来标识特定的数据帧,这样它们就可以组合到一个数据帧中使用。文件列表和
readxl
工作得很好。我已经用创建了3个excel文件
Mappe1.xlsx-表1-A1:A4-1,2,3,4
Mappe2.xlsx-表1-A1:A4-4,2,3,4
Mappe3.xlsx-表1-A1:A4-4,2,3,4
如果你使用代码
library(readxl)
library(tidyverse)
# define the names of the excel files
excelNames <- paste0('Mappe', 1:3, '.xlsx')
lapply(1:length(excelNames), function(i) {
# get current ID and rid of the file extension
currentID <- str_split(excelNames[i], '.xlsx', simplify = TRUE)[1]
# read excel file and add column with id
read_excel(
excelNames[i],
sheet = 'Tabelle1',
col_names = FALSE,
range = cell_limits(c(1, 1), c(4, 1))) %>%
mutate(ID = currentID)
}) %>%
# bind all results into one dataframe
bind_rows()
库(readxl)
图书馆(tidyverse)
#定义excel文件的名称
卓越名称%
#将所有结果绑定到一个数据帧中
绑定_行()
你应该
# A tibble: 12 x 2
...1 ID
<dbl> <chr>
1 1 Mappe1
2 2 Mappe1
3 3 Mappe1
4 4 Mappe1
5 4 Mappe2
6 2 Mappe2
7 3 Mappe2
8 4 Mappe2
9 4 Mappe3
10 2 Mappe3
11 3 Mappe3
12 4 Mappe3
#一个tible:12 x 2
…1个ID
1 Mappe1
2 Mappe1
3 3 Mappe1
4 Mappe1
5 4 Mappe2
6 2 Mappe2
7 3 Mappe2
8 4 Mappe2
9 4 Mappe3
10 2 Mappe3
11 3 Mappe3
12 4 Mappe3