将多个CSV文件中的数据读入单个ffdf对象

时间:2014-10-17 16:54:01

标签: r csv ff ffbase

是否可以立即将来自多个文件的数据加载到ff数据框(ffdf)? 可以说我有

big_file_part1.csv
big_file_part2.csv
big_file_part3.csv

我知道我可以将每个csv文件加载到一个单独的ffdf对象,然后将ffdfrbind.fill加在一起。 但这似乎是一种低效的方式,加载两次。还有更直接的方式吗?

1 个答案:

答案 0 :(得分:2)

这就是我的做法(注意我的源数据没有任何标题)。

第一步 - 确保所有文件都在同一个文件夹中。将工作目录设置为文件夹。

#load the ffbase library
library(ffbase)

#create a vector of the files that I want to load
temp = list.files(pattern="*.csv")

#create the first ffdf object for i = 1, this is necessary to establish the ff dataframe to append the rest
for (i in 1)
  mydata <- read.csv.ffdf(file=temp[i], header=FALSE, VERBOSE=TRUE
          , first.rows=100000, next.rows=100000, colClasses=NA)

#loop through the remaining objects
for (i in 2:length(temp))
  mydata <- read.csv.ffdf(x = mydata, file=temp[i], header=FALSE, VERBOSE=TRUE
            , first.rows=100000, next.rows=100000)
相关问题