상위 1000 개의 행로드
read.table 함수를 사용하여 데이터의 처음 1000 행을 로드하는 것으로 부터 시작합니다. 불필요한 factor 변환을 피하기 위해서, 사전에 데이터를 검사하고 적절한 열 유형을 미리 결정하여 col_classes라는 객체에 저장한 다음 read.table로 전달합니다.
col_classes <- c('VendorID' = "factor",
'tpep_pickup_datetime' = "character",
'tpep_dropoff_datetime' = "character",
'passenger_count' = "integer",
'trip_distance' = "numeric",
'pickup_longitude' = "numeric",
'pickup_latitude' = "numeric",
'RateCodeID' = "factor",
'store_and_fwd_flag' = "factor",
'dropoff_longitude' = "numeric",
'dropoff_latitude' = "numeric",
'payment_type' = "factor",
'fare_amount' = "numeric",
'extra' = "numeric",
'mta_tax' = "numeric",
'tip_amount' = "numeric",
'tolls_amount' = "numeric",
'improvement_surcharge' = "numeric",
'total_amount' = "numeric")
작은 데이터 샘플을 R의 data.frame으로 먼저 로드해 보는 것은 매우 좋은 개발 방법입니다. XDF 데이터에 적용하기에 앞서서, 더 쉽고 빠르게 오류를 잡아낼 수 있는 data.frame을 통하여 개발을 진행하는 것이며, 오류가 제거된 이후에 전체 데이터가 존재하는 XDF 로 개발된 내용을 적용하는 것입니다. 나중에 데이터에서 임의의 샘플을 가져 오는 방법을 배우지만, 여기에서 샘플은 단순하게 처음 1000 개의 행으로 구성합니다.
input_csv <- 'yellow_tripdata_2016-01.csv'
# 일련의 데이터 집합(chunk)을 data.frame 으로로드(테스트 용도로 좋음)
nyc_sample_df <- read.csv(input_csv, nrows = 1000, colClasses = col_classes)
head(nyc_sample_df)
VendorID tpep_pickup_datetime tpep_dropoff_datetime passenger_count trip_distance
1 2 2016-01-01 00:00:00 2016-01-01 00:00:00 2 1.10
2 2 2016-01-01 00:00:00 2016-01-01 00:00:00 5 4.90
3 2 2016-01-01 00:00:00 2016-01-01 00:00:00 1 10.54
4 2 2016-01-01 00:00:00 2016-01-01 00:00:00 1 4.75
5 2 2016-01-01 00:00:00 2016-01-01 00:00:00 3 1.76
6 2 2016-01-01 00:00:00 2016-01-01 00:18:30 2 5.52
pickup_longitude pickup_latitude RatecodeID store_and_fwd_flag dropoff_longitude
1 -73.99037 40.73470 1 N -73.98184
2 -73.98078 40.72991 1 N -73.94447
3 -73.98455 40.67957 1 N -73.95027
4 -73.99347 40.71899 1 N -73.96224
5 -73.96062 40.78133 1 N -73.97726
6 -73.98012 40.74305 1 N -73.91349
dropoff_latitude payment_type fare_amount extra mta_tax tip_amount tolls_amount
1 40.73241 2 7.5 0.5 0.5 0 0
2 40.71668 1 18.0 0.5 0.5 0 0
3 40.78893 1 33.0 0.5 0.5 0 0
4 40.65733 2 16.5 0.0 0.5 0 0
5 40.75851 2 8.0 0.0 0.5 0 0
6 40.76314 2 19.0 0.5 0.5 0 0
improvement_surcharge total_amount
1 0.3 8.8
2 0.3 19.3
3 0.3 34.3
4 0.3 17.3
5 0.3 8.8
6 0.3 20.3