맨해튼으로 필터링
우리는 이제 맨하탄 내에서만 일어난 운행에 대해서 만으로 초점을 맞춤으로써 분석 범위를 좁히어, 운행에 대한 "합리적인" 기준을 수립하도록 합니다. 데이터에 새로운 특성들을 추가하였으므로, 데이터에서 이제는 필요 없는 예전의 열들을 삭제하여 데이터가 더 빨리 처리되도록 할 수 있습니다.
input_xdf <- 'yellow_tripdata_2016_manhattan.xdf'
mht_xdf <- RxXdfData(input_xdf)
rxDataStep(nyc_xdf, mht_xdf,
rowSelection = (
passenger_count > 0 &
trip_distance >= 0 & trip_distance < 30 &
trip_duration > 0 & trip_duration < 60*60*24 &
str_detect(pickup_borough, 'Manhattan') &
str_detect(dropoff_borough, 'Manhattan') &
!is.na(pickup_nb) &
!is.na(dropoff_nb) &
fare_amount > 0),
transformPackages = "stringr",
varsToDrop = c('extra', 'mta_tax', 'improvement_surcharge', 'total_amount',
'pickup_borough', 'dropoff_borough', 'pickup_nhood', 'dropoff_nhood'),
overwrite = TRUE)
그리고 우리가 데이터의 범위를 제한하였기 때문에, 새로운 데이터 샘플을 data.frame으로 작성하는 것이 좋습니다. 마지막 샘플이었던 nyc_sample_df는 데이터의 최초 1000 개 행만 가져 왔기 때문에 그다지 좋은 샘플이 아니었습니다. 이번에는 rxDataStep을 사용하여 더 큰 데이터 집합으로 부터 전체 행의 1% 만 포함하는 임의의 데이터 샘플을 만듭니다.
mht_sample_df <- rxDataStep(mht_xdf, rowSelection = (u < .01),
transforms = list(u = runif(.rxNumRows)))
dim(mht_sample_df)
Rows Processed: 57493035
WARNING: The number of rows (574832) times the number of columns (24)
exceeds the 'maxRowsByCols' argument (3000000). Rows will be truncated.
> dim(mht_sample_df)
[1] 125000 24