加载多个文件到使用R矩阵 [英] Loading multiple files into matrix using R

查看:204
本文介绍了加载多个文件到使用R矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的编程世界,并需要加载一个文件到R和与它创建一个矩阵帮助。我可以导入单个文件,并创建和个人的基质出来。我该如何为多个文件做到这一点?我有21个文件,每个包含100行和100列,我需要导入每个文件,并把一切都放在一个阵列。


解决方案

  1. 我会使用 list.files 通过模式列出我的文件。

  2. lapply 来遍历文件列表,并创建 read.csv
  3. rbindlist 绑定都在一个大的矩阵。

      TEMP = list.files(模式=*。CSV)
    named.list< - lapply(温度,read.csv)
    库(data.table)
    files.matrix< -rbindlist(named.list)


I am new to the programming world and need help with loading a file to R and creating a matrix with it. I can import individual files and create and individual matrix out of it. How do I do this for multiple files? I have 21 files that each contain 100 rows and 100 columns and I need to import each file and put everything in a single array.

解决方案

  1. I would use list.files to list my files by pattern.
  2. lapply to loop through the list of files and create a list data.frame with read.csv
  3. rbindlist to bind all in a big matrix.

    temp = list.files(pattern="*.csv")
    named.list <- lapply(temp, read.csv)
    library(data.table)
    files.matrix <-rbindlist(named.list)
    

这篇关于加载多个文件到使用R矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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