将多个矩阵导入R中的一个数组 [英] Importing mutiple matrices to one array in R

查看:76
本文介绍了将多个矩阵导入R中的一个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have one folder and in that folder there are 24 individual folders. Each of those individual folders contains multiple files that each contain a matrix. How can I loop through the individual folders and pull out select files and put them into an array? For example, if I have one central folder and in that I have 24 folders and in each of the 24 folders there are files named file1, file2, file3, how can I pull off each file1 and put them into an array?

推荐答案

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以来,可能可以更直接地做到这一点.也许:

The request for the structure of the typical file is to fill in the devilish details. Could probably do it more directly since my first effort was initially thinking about using abind sequentially. Perhaps:

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) )

这篇关于将多个矩阵导入R中的一个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆