데이터 인사이트 스터디 내용을 관리하는 블로그 입니다.

Data Insight Study Blog

  • Join Us on Facebook!
  • Follow Us on Twitter!
  • LinkedIn
  • Subcribe to Our RSS Feed

3. Examining and Visualizing Data > Examining the Data > Examining Neighborhoods

지역(neighborhoods) 조사

"~ ." 파라미터를 rxSummary 함수에 전달하여, 데이터 상의 모든 컬럼에 대한 요약 정보를 얻을 수 있습니다.

system.time(
rxs_all <- rxSummary( ~ ., nyc_xdf)
)
Rows Processed: 69406520 
   user  system elapsed 
   0.05    0.02   85.16 

예를 들자면, 데이터에서 숫자와 관련된 열에 대한 요약은 rxs_all의 sDataFrame이라는 항목 아래의  저장됩니다.

head(rxs_all$sDataFrame)
                   Name       Mean      StdDev           Min           Max ValidObs
1              VendorID         NA          NA            NA            NA 69406520
2  tpep_pickup_datetime         NA          NA            NA            NA        0
3 tpep_dropoff_datetime         NA          NA            NA            NA        0
4       passenger_count   1.660674    1.310478        0.0000        9.0000 69406520
5         trip_distance   4.850022 4044.503422 -3390583.8000 19072628.8000 69406520
6      pickup_longitude -72.920469    8.763351     -165.0819      118.4089 69406520
  MissingObs
1          0
2          0
3          0
4          0
5          0
6          0

만약 우리가 데이터의 각 factor 열에 대한 level 수를 보여 주는 단방향 테이블을 원한다면, rxs_all을 참조하여 얻을 수 있지만, 특정 factor 열과 다른 factor열의 조합 별로 집계한 수를 보여주는 두방향의 테이블을 보려고 한다면, 올바른 수식을 요약 함수에 전달하는 것이 필요합니다. 여기에서는 rxCrossTabs 함수를 사용하여 한 지역에서 다른 지역으로 이동하는 횟수를 구합니다.

nhoods_by_borough <- rxCrossTabs( ~ pickup_nhood:pickup_borough, nyc_xdf)
nhoods_by_borough <- nhoods_by_borough$counts[[1]]
nhoods_by_borough <- as.data.frame(nhoods_by_borough)

# get the neighborhoods by borough
lnbs <- lapply(names(nhoods_by_borough), function(vv) subset(nhoods_by_borough, nhoods_by_borough[ , vv] > 0, select = vv, drop = FALSE))
lapply(lnbs, head)
[[1]]
[1] Albany
<0 rows> (or 0-length row.names)

[[2]]
[1] Buffalo
<0 rows> (or 0-length row.names)

[[3]]
             New York City-Bronx
Baychester                   125
Bedford Park                1413
City Island                   52
Country Club                 354
Eastchester                   98
Fordham                     1243

[[4]]
                   New York City-Brooklyn
Bay Ridge                            3378
Bedford-Stuyvesant                  54269
Bensonhurst                          1159
Boerum Hill                         76404
Borough Park                         8762
Brownsville                          2757

[[5]]
              New York City-Manhattan
Battery Park                   643283
Carnegie Hill                  807204
Central Park                   936840
Chelsea                       4599098
Chinatown                      211229
Clinton                       2050545

[[6]]
                         New York City-Queens
Astoria-Long Island City               303231
Auburndale                                464
Clearview                                 152
College Point                               1
Corona                                   1496
Douglastown-Little Neck                   937

[[7]]
                            New York City-Staten Island
Annandale                                             6
Ardon Heights                                        22
Bloomfield-Chelsea-Travis                            26
Charlestown-Richmond Valley                           7
Clifton                                             525
Ettingville                                          13

[[8]]
[1] Rochester
<0 rows> (or 0-length row.names)

[[9]]
[1] Syracuse
<0 rows> (or 0-length row.names)
답글 기능이 비활성화되어 있습니다