读多个文件
library(tidyverse)
library(fs)
file_paths <- fs::dir_ls("001_read_multiple_files/data")
file_paths
# 1.0 FOR LOOP ----
file_contents <- list()
for (i in seq_along(file_paths)) {
file_contents[[i]] <- read_csv(
file = file_paths[[i]]
)
}
file_contents <- set_names(file_contents, file_paths)
# 2.0 PURRR MAP ----
file_paths %>%
map(function (path) {
read_csv(path)
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
编辑 (opens new window)
上次更新: 2021/06/28, 15:34:16