0

我有一个文件夹,在那个文件夹中有 24 个单独的文件夹。这些单独的文件夹中的每一个都包含多个文件,每个文件都包含一个矩阵。如何遍历各个文件夹并提取选定文件并将它们放入数组中?例如,如果我有一个中央文件夹,并且其中有 24 个文件夹,并且在 24 个文件夹中的每个文件夹中都有名为 file1、file2、file3 的文件,我如何才能提取每个 file1 并将它们放入一个数组中?

4

1 回答 1

1
files <- list.files(path="/path/to/your/folder/")
require(abind)
arr <- do.call( abind, lapply(seq_along(list.files) , function(finum) {
                    data.matrix( read.table(file=files[finum],  ,,,devilish details) )
                    }

对典型文件结构的要求是填写恶魔般的细节。可能可以更直接地做到这一点,因为我的第一次努力最初是考虑abind按顺序使用。也许:

files <- list.files(path="/path/to/your/folder/")
require(abind)
arr <- do.call( abind, lapply(list.files , function(filnm) {
                    data.matrix( read.table(file=filnm,  ,,, devilish details) )
于 2013-04-23T23:53:55.290 回答