전체 데이터 읽기
이제 MRS를 사용하여 전체 데이터를 로드 합니다. MRS는 플랫 파일을 다음 두 가지 방식으로 처리합니다.
- 플랫 파일로 직접 작업 할 수 있습니다. 즉, 플랫 파일로 직접 읽고 쓸 수 있으며,
- 플랫 파일을 XDF(XDF는 외부 데이터 프레임-external data frame-을 나타냄) 형식으로 변환할 수 있습니다.
두 번 째 방법을 선택하여 사용하며, 선택한 이유에 대해서는 다음 섹션에서 설명합니다. 플랫 파일을 XDF로 변환하기 위하여 rxImport 함수를 사용합니다. append = "rows"를 사용하면, 여러 개의 플랫 파일을 단일 XDF 파일로 결합할 수 있습니다.
input_xdf <- 'yellow_tripdata_2016.xdf'
library(lubridate)
most_recent_date <- ymd("2016-07-01") # 일자 정보는 의미가 없음
st <- Sys.time()
for(ii in 1:6) { # 각각의 월 데이터를 가져와서 첫 달 데이터에 추가
file_date <- most_recent_date - months(ii)
input_csv <- sprintf('yellow_tripsample_%s.csv', substr(file_date, 1, 7))
append <- if (ii == 1) "none" else "rows"
rxImport(input_csv, input_xdf, colClasses = col_classes, overwrite = TRUE, append = append)
print(input_csv)
}
Sys.time() - st # stores the time it took to import
Rows Processed: 10906858
[1] "yellow_tripdata_2016-01.csv"
Rows Processed: 11382049
[1] "yellow_tripdata_2016-02.csv"
Rows Processed: 12210952
[1] "yellow_tripdata_2016-03.csv"
Rows Processed: 11934338
[1] "yellow_tripdata_2016-04.csv"
Rows Processed: 11836853
[1] "yellow_tripdata_2016-05.csv"
Rows Processed: 11135470
[1] "yellow_tripdata_2016-06.csv"
Time difference of 13.96592 mins