더북(TheBook)

이 절에서는 1974년에 미국의 모터 트렌드 잡지에 실린 1973 ~ 1974년 자동차 모델의 연료 소비, 10가지 디자인 요소, 성능을 비교한 mtcars 데이터에 대해 요약해본다. 다음은 mtcars 데이터의 모양이다.

> str(mtcars)
'data.frame':    32 obs. of  11 variables:
 $ mpg : num  21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ...
 $ cyl : num  6 6 4 6 8 6 8 4 4 6 ...
 $ disp: num  160 160 108 258 360 ...
 $ hp  : num  110 110 93 110 175 105 245 62 95 123 ...
 $ drat: num  3.9 3.9 3.85 3.08 3.15 2.76 3.21 3.69 3.92 3.92 ...
 $ wt  : num  2.62 2.88 2.32 3.21 3.44 ...
 $ qsec: num  16.5 17 18.6 19.4 17 ...
 $ vs  : num  0 0 1 1 0 1 0 1 1 1 ...
 $ am  : num  1 1 1 0 0 0 0 0 0 0 ...
 $ gear: num  4 4 4 3 3 3 3 4 4 4 ...
 $ carb: num  4 4 1 1 2 1 4 2 2 4 ...

이 데이터에 describe( )를 적용해보자. describe( )는 summary( )와 유사하지만 결측치의 수(missing), 서로 다른 값의 수(unique), 데이터의 분포, 합, 평균 등 좀 더 다양한 요약 정보를 제시한다.

> describe(mtcars)
mtcars

 11 Variables    32 Observations
------------------------------------------------------------------------------------
mpg
      n missing  unique     Mean      .05      .10      .25      .50      .75      .90      .95
     32       0      25    20.09    12.00    14.34    15.43    19.20    22.80    30.09    31.30

lowest : 10.4 13.3 14.3 14.7 15.0, highest: 26.0 27.3 30.4 32.4 33.9
------------------------------------------------------------------------------------
cyl
      n missing  unique     Mean
     32       0       3    6.188

4 (11, 34%), 6 (7, 22%), 8 (14, 44%)
------------------------------------------------------------------------------------
disp
      n missing  unique      Mean      .05      .10      .25      .50      .75      .90      .95
     32       0      27     230.7    77.35    80.61   120.83   196.30   326.00   396.00   449.00

lowest : 71.1 75.7 78.7 79.0 95.1, highest: 360.0 400.0 440.0 460.0 472.0
------------------------------------------------------------------------------------
hp
      n missing  unique      Mean      .05      .10      .25      .50      .75      .90      .95
     32       0      22     146.7    63.65    66.00    96.50   123.00   180.00   243.50   253.55

lowest : 52 62 65 66 91, highest: 215 230 245 264 335
------------------------------------------------------------------------------------
drat
      n missing  unique      Mean      .05      .10      .25      .50      .75      .90      .95
     32       0      22     3.597    2.853    3.007    3.080    3.695    3.920    4.209    4.314

lowest : 2.76 2.93 3.00 3.07 3.08, highest: 4.08 4.11 4.22 4.43 4.93
------------------------------------------------------------------------------------
wt
      n missing  unique      Mean      .05      .10      .25      .50      .75      .90      .95
     32       0      29     3.217    1.736    1.956    2.581    3.325    3.610    4.048    5.293

lowest : 1.513 1.615 1.835 1.935 2.140, highest: 3.845 4.070 5.250 5.345 5.424
------------------------------------------------------------------------------------
qsec
      n missing  unique      Mean      .05      .10      .25      .50      .75      .90      .95
     32       0      30     17.85    15.05    15.53    16.89    17.71    18.90    19.99    20.10

lowest : 14.50 14.60 15.41 15.50 15.84, highest: 19.90 20.00 20.01 20.22 22.90
------------------------------------------------------------------------------------
vs
      n missing  unique      Sum      Mean
     32       0       2       14    0.4375
------------------------------------------------------------------------------------
am
      n missing  unique      Sum      Mean
     32       0        2      13    0.4062
------------------------------------------------------------------------------------
gear
      n missing  unique     Mean
     32       0       3    3.688
3 (15, 47%), 4 (12, 38%), 5 (5, 16%)
------------------------------------------------------------------------------------
carb
      n missing  unique     Mean
     32       0       6    2.812

           1  2 3  4 6 8
Frequency  7 10 3 10 1 1
%         22 31 9 31 3 3
------------------------------------------------------------------------------------
>

같은 데이터에 summary( )를 적용한 결과는 다음과 같다.

> summary(mtcars)
     mpg             cyl             disp             hp            drat
Min.   :10.40   Min.   :4.000   Min.   : 71.1   Min.   : 52.0   Min.   :2.760
1st Qu.:15.43   1st Qu.:4.000   1st Qu.:120.8   1st Qu.: 96.5   1st Qu.:3.080
Median :19.20   Median :6.000   Median :196.3   Median :123.0   Median :3.695
Mean   :20.09   Mean   :6.188   Mean   :230.7   Mean   :146.7   Mean   :3.597
3rd Qu.:22.80   3rd Qu.:8.000   3rd Qu.:326.0   3rd Qu.:180.0   3rd Qu.:3.920
Max.   :33.90   Max.   :8.000   Max.   :472.0   Max.   :335.0   Max.   :4.930

      wt             qsec             vs               am              gear
Min.   :1.513   Min.   :14.50   Min.   :0.0000   Min.   :0.0000   Min.   :3.000
1st Qu.:2.581   1st Qu.:16.89   1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:3.000
Median :3.325   Median :17.71   Median :0.0000   Median :0.0000   Median :4.000
Mean   :3.217   Mean   :17.85   Mean   :0.4375   Mean   :0.4062   Mean   :3.688
3rd Qu.:3.610   3rd Qu.:18.90   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:4.000
Max.   :5.424   Max.   :22.90   Max.   :1.0000   Max.   :1.0000   Max.   :5.000

     carb
Min.   :1.000
1st Qu.:2.000
Median :2.000
Mean   :2.812
3rd Qu.:4.000
Max.   :8.000
신간 소식 구독하기
뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.