将多个csv文件从一个文件夹读入R中的单个数据帧 [英] Reading multiple csv files from a folder into a single dataframe in R
本文介绍了将多个csv文件从一个文件夹读入R中的单个数据帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含332个csv文件的文件夹。文件名如下001.csv,002.csv,003.csv,............,330.csv,331.csv,332.csv。所有文件都有相同数量的变量和相同的格式。
I have a folder containing 332 csv files. The name of the files are as follows 001.csv, 002.csv, 003.csv, ............ , 330.csv, 331.csv , 332.csv . All the files have same number of variables and same format.
我需要读取一个数据帧中的所有文件。我一直在阅读每一个然后使用rbind,但这太麻烦了。
I need to read all the files in one dataframe. I have been reading each one and then using rbind, but this is too cumbersome.
需要帮助。
推荐答案
尝试lapply和do.call
Try lapply and do.call
file_names <- dir() #where you have your files
your_data_frame <- do.call(rbind,lapply(file_names,read.csv))
这篇关于将多个csv文件从一个文件夹读入R中的单个数据帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文