我有许多RData
文件,其中存储了特定信息。
for (filename in c("file1", "file2", "file3")) {
a = tibble(letters = sample(LETTERS, 10),
numbers = sample(1:100, 10))
save(a, file = paste0("tmp/", filename, ".RData")) }
我现在想在嵌套 tibble 中读取存储在这些文件中的数据以进行进一步分析。
但是,我不知道如何加载存储在这些文件中的数据,最终以 tibble 结尾。
ndf <- tibble(path = list.files("tmp", full.names = TRUE),
file = basename(path),
a = purrr::map(path, function(path) {
load(path) # does not do what I want
}))
然后我想继续我的分析,例如
analysis <- ndf %>%
mutate(mean = purrr::map_dbl(a, function(a) mean(a$numbers)))
问题是 load 旨在将检索到的对象存储在环境中,并且不返回检索到的对象列表或类似的。因此,似乎需要另一种解决方案。