2014-10-17 2 views
0

여러 파일의 데이터를 ff 데이터 프레임 (ffdf)에 즉시로드 할 수 있습니까? 내가 별도의 ffdf 개체에 각 csv 파일을로드 할 수 알아야하고 그들을 함께 ffdfrbind.fill 내가여러 개의 CSV 파일에서 단일 ffdf 객체로 데이터 읽기

big_file_part1.csv 
big_file_part2.csv 
big_file_part3.csv 

이 있다고 할 수 있습니다. 하지만 이는 비효율적 인 것처럼 보입니다. 물건을 두 번로드합니다. 직접적인 방법이 있습니까?

+0

파일의 크기는 얼마나됩니까? –

+0

실제로 각 파일에 27 개의 파일이 있습니다. 총 10GB이지만 대부분의 상태는 작고 (<100MB) 두 개의 상태가 다소 큽니다 (> 4GB> 내 RAM) – LucasMation

+2

read.csv.ffdf의 인수 'x'를 사용하여 데이터를 기존 ffdf에 추가 할 수 있습니다. 다른 csv 파일의 구조가 같은 경우. – jwijffels

답변

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) 
관련 문제