将多个矩阵导入R中的一个数组

时间:2013-04-23 23:01:32

标签: arrays r matrix

我有一个文件夹,在该文件夹中有24个单独的文件夹。每个单独的文件夹都包含多个文件,每个文件都包含一个矩阵。如何遍历各个文件夹并拉出选择文件并将它们放入数组中?例如,如果我有一个中央文件夹,并且我有24个文件夹,并且在24个文件夹中的每个文件夹中都有名为file1,file2,file3的文件,如何将每个文件1拉出并将它们放入数组中?

1 个答案:

答案 0 :(得分: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) )