統計量

Sta([D],r=[F]:列/T:行,s:統計値 ex.’sum,mean,sd’,d:小数桁)
s: sum,mean,median,mid,min,max,sd,sdp,var,varp,q1,q2,q3,rng,gini,entropy, gm,gmz,gsd,gsdz,kurt,kurt.r,ldi,pareto,skew,skew.e,skew.r

D=Ip('x45') #簡単な例(数値行列:4x5)
## File: x45.txt / Class: data.frame / Rows: 4 / Columns: 5
##  
##    A  B  C  D  E 
## w1 10 19 14  7 12
## w2 11  7 10  0  1
## w3  0  0  1 12  1
## w4  0  1  2  3  3
S=Sta(s='count,sum'); Dt(S,j=T) #個数, 和:列
## Class: matrix, array / Rows: 2 / Columns: 5
##  
##        A  B  C  D  E
## count  4  4  4  4  4
## sum   21 27 27 22 17
S=Sta(s='count,sum',r=T); Dt(S) #個数, 和:行(r=T)
## Class: matrix, array / Rows: 4 / Columns: 2
##  
##    count sum
## w1 5     62 
## w2 5     29 
## w3 5     14 
## w4 5      9
D=iris; Dt() #データ:iris
## Class: data.frame / Rows: 150 / Columns: 5
##  
##    Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1  5.1          3.5         1.4          0.2         setosa 
## 2  4.9          3.0         1.4          0.2         setosa 
## 3  4.7          3.2         1.3          0.2         setosa 
## 4  4.6          3.1         1.5          0.2         setosa 
## 5  5.0          3.6         1.4          0.2         setosa 
## 6  5.4          3.9         1.7          0.4         setosa 
## 7  4.6          3.4         1.4          0.3         setosa 
## 8  5.0          3.4         1.5          0.2         setosa 
## 9  4.4          2.9         1.4          0.2         setosa 
## 10 4.9          3.1         1.5          0.1         setosa
D=Dat(c=1:4); Dt() #数値列選択
## Class: data.frame / Rows: 150 / Columns: 4
##  
##    Sepal.Length Sepal.Width Petal.Length Petal.Width
## 1  5.1          3.5         1.4          0.2        
## 2  4.9          3.0         1.4          0.2        
## 3  4.7          3.2         1.3          0.2        
## 4  4.6          3.1         1.5          0.2        
## 5  5.0          3.6         1.4          0.2        
## 6  5.4          3.9         1.7          0.4        
## 7  4.6          3.4         1.4          0.3        
## 8  5.0          3.4         1.5          0.2        
## 9  4.4          2.9         1.4          0.2        
## 10 4.9          3.1         1.5          0.1
S=Sta(s='min,q1,median,mean,q3,max',d=3); Dt(S)
## Class: matrix, array / Rows: 6 / Columns: 4
##  
##        Sepal.Length Sepal.Width Petal.Length Petal.Width
## min    4.300        2.000       1.000        0.100      
## q1     5.100        2.800       1.600        0.300      
## median 5.800        3.000       4.350        1.300      
## mean   5.843        3.057       3.758        1.199      
## q3     6.400        3.300       5.100        1.800      
## max    7.900        4.400       6.900        2.500
summary(D) #参考: 比較
##   Sepal.Length    Sepal.Width     Petal.Length    Petal.Width   
##  Min.   :4.300   Min.   :2.000   Min.   :1.000   Min.   :0.100  
##  1st Qu.:5.100   1st Qu.:2.800   1st Qu.:1.600   1st Qu.:0.300  
##  Median :5.800   Median :3.000   Median :4.350   Median :1.300  
##  Mean   :5.843   Mean   :3.057   Mean   :3.758   Mean   :1.199  
##  3rd Qu.:6.400   3rd Qu.:3.300   3rd Qu.:5.100   3rd Qu.:1.800  
##  Max.   :7.900   Max.   :4.400   Max.   :6.900   Max.   :2.500
D=diamonds; Dt() #データ例:ダイヤモンド(df)
## Class: tbl_df, tbl, data.frame / Rows: 53940 / Columns: 10
##  
##    carat cut       color clarity depth table price x    y    z   
## 1  0.23  Ideal     E     SI2     61.5  55    326   3.95 3.98 2.43
## 2  0.21  Premium   E     SI1     59.8  61    326   3.89 3.84 2.31
## 3  0.23  Good      E     VS1     56.9  65    327   4.05 4.07 2.31
## 4  0.29  Premium   I     VS2     62.4  58    334   4.20 4.23 2.63
## 5  0.31  Good      J     SI2     63.3  58    335   4.34 4.35 2.75
## 6  0.24  Very Good J     VVS2    62.8  57    336   3.94 3.96 2.48
## 7  0.24  Very Good I     VVS1    62.3  57    336   3.95 3.98 2.47
## 8  0.26  Very Good H     SI1     61.9  55    337   4.07 4.11 2.53
## 9  0.22  Fair      E     VS2     65.1  61    337   3.87 3.78 2.49
## 10 0.23  Very Good H     VS1     59.4  61    338   4.00 4.05 2.39
D=Dat(c='ca,p,x,y,z'); Dt() #数値列選択
## Class: tbl_df, tbl, data.frame / Rows: 53940 / Columns: 5
##  
##    carat price x    y    z   
## 1  0.23  326   3.95 3.98 2.43
## 2  0.21  326   3.89 3.84 2.31
## 3  0.23  327   4.05 4.07 2.31
## 4  0.29  334   4.20 4.23 2.63
## 5  0.31  335   4.34 4.35 2.75
## 6  0.24  336   3.94 3.96 2.48
## 7  0.24  336   3.95 3.98 2.47
## 8  0.26  337   4.07 4.11 2.53
## 9  0.22  337   3.87 3.78 2.49
## 10 0.23  338   4.00 4.05 2.39
S=Sta(s='min,q1,median,mean,q3,max',d=3); Dt(S)
## Class: matrix, array / Rows: 6 / Columns: 5
##  
##        carat price    x      y      z     
## min    0.200   326.00  0.000  0.000  0.000
## q1     0.400   950.00  4.710  4.720  2.910
## median 0.700  2401.00  5.700  5.710  3.530
## mean   0.798  3932.80  5.731  5.735  3.539
## q3     1.040  5324.25  6.540  6.540  4.040
## max    5.010 18823.00 10.740 58.900 31.800
summary(D) #参考: 比較
##      carat            price             x                y         
##  Min.   :0.2000   Min.   :  326   Min.   : 0.000   Min.   : 0.000  
##  1st Qu.:0.4000   1st Qu.:  950   1st Qu.: 4.710   1st Qu.: 4.720  
##  Median :0.7000   Median : 2401   Median : 5.700   Median : 5.710  
##  Mean   :0.7979   Mean   : 3933   Mean   : 5.731   Mean   : 5.735  
##  3rd Qu.:1.0400   3rd Qu.: 5324   3rd Qu.: 6.540   3rd Qu.: 6.540  
##  Max.   :5.0100   Max.   :18823   Max.   :10.740   Max.   :58.900  
##        z         
##  Min.   : 0.000  
##  1st Qu.: 2.910  
##  Median : 3.530  
##  Mean   : 3.539  
##  3rd Qu.: 4.040  
##  Max.   :31.800
D=USArrests; Dt() #データ:USArrests
## Class: data.frame / Rows: 50 / Columns: 4
##  
##             Murder Assault UrbanPop Rape
## Alabama     13.2   236     58       21.2
## Alaska      10.0   263     48       44.5
## Arizona      8.1   294     80       31.0
## Arkansas     8.8   190     50       19.5
## California   9.0   276     91       40.6
## Colorado     7.9   204     78       38.7
## Connecticut  3.3   110     77       11.1
## Delaware     5.9   238     72       15.8
## Florida     15.4   335     80       31.9
## Georgia     17.4   211     60       25.8
D=Dat(c='1,2,4') #数値列選択
S=Sta(); Dt(S) #デフォルト:sum,mean,sd 
## Class: matrix, array / Rows: 3 / Columns: 3
##  
##      Murder Assault Rape  
## sum  389.4  8538.0  1061.6
## mean   7.8   170.8    21.2
## sd     4.4    83.3     9.4
summary(D) #参考: 比較 summary()
##      Murder          Assault           Rape      
##  Min.   : 0.800   Min.   : 45.0   Min.   : 7.30  
##  1st Qu.: 4.075   1st Qu.:109.0   1st Qu.:15.07  
##  Median : 7.250   Median :159.0   Median :20.10  
##  Mean   : 7.788   Mean   :170.8   Mean   :21.23  
##  3rd Qu.:11.250   3rd Qu.:249.0   3rd Qu.:26.18  
##  Max.   :17.400   Max.   :337.0   Max.   :46.00

クロス集計

Cross(df=D,x=0,v=0,n=0,d=0,m=F,t=F)
([df], x:個体列(単複), v:変数列(単複),n:数値列(単),t:入力列名付加)

D=Ip('mozi') #簡単なデータ例 文字行列 (df)
## File: mozi.txt / Class: data.frame / Rows: 10 / Columns: 3
##  
##    A  B  C 
## 1  a1 b1 c2
## 2  a1 b2 c3
## 3  a1 b3 c1
## 4  a1 b1 c3
## 5  a1 b1 c2
## 6  a2 b2 c1
## 7  a2 b2 c3
## 8  a2 b1 c1
## 9  a2 b3 c1
## 10 a2 b2 c2
Cross(x=0,v=1:3) #ダミー行列(x=0), 列(v)=1:3
##    a1 a2 b1 b2 b3 c1 c2 c3
## 1   1  0  1  0  0  0  1  0
## 2   1  0  0  1  0  0  0  1
## 3   1  0  0  0  1  1  0  0
## 4   1  0  1  0  0  0  0  1
## 5   1  0  1  0  0  0  1  0
## 6   0  1  0  1  0  1  0  0
## 7   0  1  0  1  0  0  0  1
## 8   0  1  1  0  0  1  0  0
## 9   0  1  0  0  1  1  0  0
## 10  0  1  0  1  0  0  1  0
D=Ip('santander') #Santander 録音調査:多次元文字行列
## File: santander.txt / Class: data.frame / Rows: 3962 / Columns: 4
##  
##    Forma Sexo Edad Nivel
## 1  eh    H    E1   N1   
## 2  eh    H    E1   N1   
## 3  eh    H    E1   N1   
## 4  eh    H    E1   N1   
## 5  eh    H    E1   N1   
## 6  eh    H    E1   N1   
## 7  eh    H    E1   N1   
## 8  eh    H    E1   N1   
## 9  eh    H    E1   N1   
## 10 eh    H    E1   N1
Cross(D,x=1) #個体x=1列
##                Sum
## ah              75
## ay              48
## bueno          949
## claramente      13
## claro          336
## directamente    20
## efectivamente   30
## eh            1145
## exactamente     46
## generalmente    25
## hm             101
## hola            25
## jo             102
## joder           29
## jolín           13
## madre mía       15
## mm             412
## muchísimo       95
## normalmente     75
## oye             40
## perfectamente   17
## pff             62
## prácticamente   22
## realmente       41
## simplemente     31
## sinceramente    13
## totalmente      43
## uhum            57
## uy              19
## vale            46
## vamos           17
Cross(D,x=1,v=2) #個体x=1列, 変数v=2列
##                 H   M
## ah             24  51
## ay              8  40
## bueno         488 461
## claramente     13   0
## claro         118 218
## directamente   12   8
## efectivamente  11  19
## eh            828 317
## exactamente    39   7
## generalmente   18   7
## hm             30  71
## hola           17   8
## jo              4  98
## joder          25   4
## jolín           0  13
## madre mía       4  11
## mm            223 189
## muchísimo      19  76
## normalmente    62  13
## oye            30  10
## perfectamente   6  11
## pff            24  38
## prácticamente  14   8
## realmente      29  12
## simplemente    24   7
## sinceramente    8   5
## totalmente     17  26
## uhum           30  27
## uy              3  16
## vale           14  32
## vamos           4  13
Cross(D,x=1,v=3) #個体x=1列, 変数v=3列
##                E1  E2  E3
## ah             16  13  46
## ay              4   1  43
## bueno         280 347 322
## claramente      0  10   3
## claro          54  98 184
## directamente   10   9   1
## efectivamente   0   7  23
## eh            329 456 360
## exactamente     0  26  20
## generalmente    4  14   7
## hm             29  31  41
## hola            4  19   2
## jo              3  98   1
## joder           4  12  13
## jolín           1  10   2
## madre mía       0   8   7
## mm            133 163 116
## muchísimo      20  52  23
## normalmente    18  14  43
## oye             4  22  14
## perfectamente   2   3  12
## pff            15  27  20
## prácticamente   9   7   6
## realmente      28   4   9
## simplemente    19   6   6
## sinceramente    3   6   4
## totalmente     12  28   3
## uhum            9  40   8
## uy              2   7  10
## vale            9  27  10
## vamos          11   3   3
Cross(D,x=1,v=4) #個体x=1列, 変数v=4列
##                N1  N2  N3
## ah             21  40  14
## ay              7  32   9
## bueno         362 253 334
## claramente     11   1   1
## claro         128  90 118
## directamente   13   6   1
## efectivamente   1   6  23
## eh            505 290 350
## exactamente    17   7  22
## generalmente    0  14  11
## hm             48  17  36
## hola            8  14   3
## jo              5  96   1
## joder          12  16   1
## jolín           2  10   1
## madre mía       1   9   5
## mm            120 132 160
## muchísimo      41  32  22
## normalmente    20   7  48
## oye            17  15   8
## perfectamente   3   6   8
## pff            12  44   6
## prácticamente   2  15   5
## realmente      18   4  19
## simplemente     7  10  14
## sinceramente    6   7   0
## totalmente      1  26  16
## uhum            8   4  45
## uy              8  10   1
## vale            8  31   7
## vamos           2  11   4
Cross(D,x=1,v=2:4) #個体x=1列, 変数v=2:4列
##                 H   M  E1  E2  E3  N1  N2  N3
## ah             24  51  16  13  46  21  40  14
## ay              8  40   4   1  43   7  32   9
## bueno         488 461 280 347 322 362 253 334
## claramente     13   0   0  10   3  11   1   1
## claro         118 218  54  98 184 128  90 118
## directamente   12   8  10   9   1  13   6   1
## efectivamente  11  19   0   7  23   1   6  23
## eh            828 317 329 456 360 505 290 350
## exactamente    39   7   0  26  20  17   7  22
## generalmente   18   7   4  14   7   0  14  11
## hm             30  71  29  31  41  48  17  36
## hola           17   8   4  19   2   8  14   3
## jo              4  98   3  98   1   5  96   1
## joder          25   4   4  12  13  12  16   1
## jolín           0  13   1  10   2   2  10   1
## madre mía       4  11   0   8   7   1   9   5
## mm            223 189 133 163 116 120 132 160
## muchísimo      19  76  20  52  23  41  32  22
## normalmente    62  13  18  14  43  20   7  48
## oye            30  10   4  22  14  17  15   8
## perfectamente   6  11   2   3  12   3   6   8
## pff            24  38  15  27  20  12  44   6
## prácticamente  14   8   9   7   6   2  15   5
## realmente      29  12  28   4   9  18   4  19
## simplemente    24   7  19   6   6   7  10  14
## sinceramente    8   5   3   6   4   6   7   0
## totalmente     17  26  12  28   3   1  26  16
## uhum           30  27   9  40   8   8   4  45
## uy              3  16   2   7  10   8  10   1
## vale           14  32   9  27  10   8  31   7
## vamos           4  13  11   3   3   2  11   4
Cross(D,x='F',v='S,E,N') #同: 変数4列を頭文字で指定
##                 H   M  E1  E2  E3  N1  N2  N3
## ah             24  51  16  13  46  21  40  14
## ay              8  40   4   1  43   7  32   9
## bueno         488 461 280 347 322 362 253 334
## claramente     13   0   0  10   3  11   1   1
## claro         118 218  54  98 184 128  90 118
## directamente   12   8  10   9   1  13   6   1
## efectivamente  11  19   0   7  23   1   6  23
## eh            828 317 329 456 360 505 290 350
## exactamente    39   7   0  26  20  17   7  22
## generalmente   18   7   4  14   7   0  14  11
## hm             30  71  29  31  41  48  17  36
## hola           17   8   4  19   2   8  14   3
## jo              4  98   3  98   1   5  96   1
## joder          25   4   4  12  13  12  16   1
## jolín           0  13   1  10   2   2  10   1
## madre mía       4  11   0   8   7   1   9   5
## mm            223 189 133 163 116 120 132 160
## muchísimo      19  76  20  52  23  41  32  22
## normalmente    62  13  18  14  43  20   7  48
## oye            30  10   4  22  14  17  15   8
## perfectamente   6  11   2   3  12   3   6   8
## pff            24  38  15  27  20  12  44   6
## prácticamente  14   8   9   7   6   2  15   5
## realmente      29  12  28   4   9  18   4  19
## simplemente    24   7  19   6   6   7  10  14
## sinceramente    8   5   3   6   4   6   7   0
## totalmente     17  26  12  28   3   1  26  16
## uhum           30  27   9  40   8   8   4  45
## uy              3  16   2   7  10   8  10   1
## vale           14  32   9  27  10   8  31   7
## vamos           4  13  11   3   3   2  11   4
Cross(D,x=1:2,v=3:4) #個体x=1:2列, 変数v=3:4列
##                  E1  E2  E3  N1  N2  N3
## ah_H              6   6  12   3  12   9
## ah_M             10   7  34  18  28   5
## ay_H              1   0   7   0   4   4
## ay_M              3   1  36   7  28   5
## bueno_H         177 204 107 191 148 149
## bueno_M         103 143 215 171 105 185
## claramente_H      0  10   3  11   1   1
## claro_H           6  64  48  23  57  38
## claro_M          48  34 136 105  33  80
## directamente_H    4   7   1   8   3   1
## directamente_M    6   2   0   5   3   0
## efectivamente_H   0   1  10   1   0  10
## efectivamente_M   0   6  13   0   6  13
## eh_H            281 279 268 424 147 257
## eh_M             48 177  92  81 143  93
## exactamente_H     0  21  18  17   4  18
## exactamente_M     0   5   2   0   3   4
## generalmente_H    4  14   0   0  14   4
## generalmente_M    0   0   7   0   0   7
## hm_H              3   6  21   5   2  23
## hm_M             26  25  20  43  15  13
## hola_H            0  16   1   2  13   2
## hola_M            4   3   1   6   1   1
## jo_H              1   2   1   1   2   1
## jo_M              2  96   0   4  94   0
## joder_H           1  11  13   9  15   1
## joder_M           3   1   0   3   1   0
## jolín_M           1  10   2   2  10   1
## madre mía_H       0   4   0   1   3   0
## madre mía_M       0   4   7   0   6   5
## mm_H             79 105  39 100  43  80
## mm_M             54  58  77  20  89  80
## muchísimo_H       6   4   9   7  10   2
## muchísimo_M      14  48  14  34  22  20
## normalmente_H    10  12  40  20   4  38
## normalmente_M     8   2   3   0   3  10
## oye_H             4  20   6  15  13   2
## oye_M             0   2   8   2   2   6
## perfectamente_H   2   0   4   1   4   1
## perfectamente_M   0   3   8   2   2   7
## pff_H             0   6  18   3  15   6
## pff_M            15  21   2   9  29   0
## prácticamente_H   8   3   3   0  12   2
## prácticamente_M   1   4   3   2   3   3
## realmente_H      23   2   4  18   1  10
## realmente_M       5   2   5   0   3   9
## simplemente_H    17   2   5   5   8  11
## simplemente_M     2   4   1   2   2   3
## sinceramente_H    2   3   3   5   3   0
## sinceramente_M    1   3   1   1   4   0
## totalmente_H     12   3   2   1   1  15
## totalmente_M      0  25   1   0  25   1
## uhum_H            4  21   5   5   0  25
## uhum_M            5  19   3   3   4  20
## uy_H              1   1   1   2   1   0
## uy_M              1   6   9   6   9   1
## vale_H            0   6   8   3   6   5
## vale_M            9  21   2   5  25   2
## vamos_H           0   2   2   1   3   0
## vamos_M          11   1   1   1   8   4
Cross(D,x=2:1,v=3:4) #個体x=2:1列 順番を変える
##                  E1  E2  E3  N1  N2  N3
## H_ah              6   6  12   3  12   9
## H_ay              1   0   7   0   4   4
## H_bueno         177 204 107 191 148 149
## H_claramente      0  10   3  11   1   1
## H_claro           6  64  48  23  57  38
## H_directamente    4   7   1   8   3   1
## H_efectivamente   0   1  10   1   0  10
## H_eh            281 279 268 424 147 257
## H_exactamente     0  21  18  17   4  18
## H_generalmente    4  14   0   0  14   4
## H_hm              3   6  21   5   2  23
## H_hola            0  16   1   2  13   2
## H_jo              1   2   1   1   2   1
## H_joder           1  11  13   9  15   1
## H_madre mía       0   4   0   1   3   0
## H_mm             79 105  39 100  43  80
## H_muchísimo       6   4   9   7  10   2
## H_normalmente    10  12  40  20   4  38
## H_oye             4  20   6  15  13   2
## H_perfectamente   2   0   4   1   4   1
## H_pff             0   6  18   3  15   6
## H_prácticamente   8   3   3   0  12   2
## H_realmente      23   2   4  18   1  10
## H_simplemente    17   2   5   5   8  11
## H_sinceramente    2   3   3   5   3   0
## H_totalmente     12   3   2   1   1  15
## H_uhum            4  21   5   5   0  25
## H_uy              1   1   1   2   1   0
## H_vale            0   6   8   3   6   5
## H_vamos           0   2   2   1   3   0
## M_ah             10   7  34  18  28   5
## M_ay              3   1  36   7  28   5
## M_bueno         103 143 215 171 105 185
## M_claro          48  34 136 105  33  80
## M_directamente    6   2   0   5   3   0
## M_efectivamente   0   6  13   0   6  13
## M_eh             48 177  92  81 143  93
## M_exactamente     0   5   2   0   3   4
## M_generalmente    0   0   7   0   0   7
## M_hm             26  25  20  43  15  13
## M_hola            4   3   1   6   1   1
## M_jo              2  96   0   4  94   0
## M_joder           3   1   0   3   1   0
## M_jolín           1  10   2   2  10   1
## M_madre mía       0   4   7   0   6   5
## M_mm             54  58  77  20  89  80
## M_muchísimo      14  48  14  34  22  20
## M_normalmente     8   2   3   0   3  10
## M_oye             0   2   8   2   2   6
## M_perfectamente   0   3   8   2   2   7
## M_pff            15  21   2   9  29   0
## M_prácticamente   1   4   3   2   3   3
## M_realmente       5   2   5   0   3   9
## M_simplemente     2   4   1   2   2   3
## M_sinceramente    1   3   1   1   4   0
## M_totalmente      0  25   1   0  25   1
## M_uhum            5  19   3   3   4  20
## M_uy              1   6   9   6   9   1
## M_vale            9  21   2   5  25   2
## M_vamos          11   1   1   1   8   4
D=HairEyeColor #イギリス人の髪と目の色 Datos: HairEyeColor
Cross(x=0,v=1:3,n=4)#個体x=0:行名, 変数v=1:3列, n=4列合計
##    Black Brown Red Blond Brown Blue Hazel Green Male Female
## 1     32     0   0     0    32    0     0     0   32      0
## 2      0    53   0     0    53    0     0     0   53      0
## 3      0     0  10     0    10    0     0     0   10      0
## 4      0     0   0     3     3    0     0     0    3      0
## 5     11     0   0     0     0   11     0     0   11      0
## 6      0    50   0     0     0   50     0     0   50      0
## 7      0     0  10     0     0   10     0     0   10      0
## 8      0     0   0    30     0   30     0     0   30      0
## 9     10     0   0     0     0    0    10     0   10      0
## 10     0    25   0     0     0    0    25     0   25      0
## 11     0     0   7     0     0    0     7     0    7      0
## 12     0     0   0     5     0    0     5     0    5      0
## 13     3     0   0     0     0    0     0     3    3      0
## 14     0    15   0     0     0    0     0    15   15      0
## 15     0     0   7     0     0    0     0     7    7      0
## 16     0     0   0     8     0    0     0     8    8      0
## 17    36     0   0     0    36    0     0     0    0     36
## 18     0    66   0     0    66    0     0     0    0     66
## 19     0     0  16     0    16    0     0     0    0     16
## 20     0     0   0     4     4    0     0     0    0      4
## 21     9     0   0     0     0    9     0     0    0      9
## 22     0    34   0     0     0   34     0     0    0     34
## 23     0     0   7     0     0    7     0     0    0      7
## 24     0     0   0    64     0   64     0     0    0     64
## 25     5     0   0     0     0    0     5     0    0      5
## 26     0    29   0     0     0    0    29     0    0     29
## 27     0     0   7     0     0    0     7     0    0      7
## 28     0     0   0     5     0    0     5     0    0      5
## 29     2     0   0     0     0    0     0     2    0      2
## 30     0    14   0     0     0    0     0    14    0     14
## 31     0     0   7     0     0    0     0     7    0      7
## 32     0     0   0     8     0    0     0     8    0      8
Cross(x=0,v=1:3,n=4,t=T) #同 + t=T:入力列名付加)
##    Hair.Black Hair.Brown Hair.Red Hair.Blond Eye.Brown Eye.Blue Eye.Hazel
## 1          32          0        0          0        32        0         0
## 2           0         53        0          0        53        0         0
## 3           0          0       10          0        10        0         0
## 4           0          0        0          3         3        0         0
## 5          11          0        0          0         0       11         0
## 6           0         50        0          0         0       50         0
## 7           0          0       10          0         0       10         0
## 8           0          0        0         30         0       30         0
## 9          10          0        0          0         0        0        10
## 10          0         25        0          0         0        0        25
## 11          0          0        7          0         0        0         7
## 12          0          0        0          5         0        0         5
## 13          3          0        0          0         0        0         0
## 14          0         15        0          0         0        0         0
## 15          0          0        7          0         0        0         0
## 16          0          0        0          8         0        0         0
## 17         36          0        0          0        36        0         0
## 18          0         66        0          0        66        0         0
## 19          0          0       16          0        16        0         0
## 20          0          0        0          4         4        0         0
## 21          9          0        0          0         0        9         0
## 22          0         34        0          0         0       34         0
## 23          0          0        7          0         0        7         0
## 24          0          0        0         64         0       64         0
## 25          5          0        0          0         0        0         5
## 26          0         29        0          0         0        0        29
## 27          0          0        7          0         0        0         7
## 28          0          0        0          5         0        0         5
## 29          2          0        0          0         0        0         0
## 30          0         14        0          0         0        0         0
## 31          0          0        7          0         0        0         0
## 32          0          0        0          8         0        0         0
##    Eye.Green Sex.Male Sex.Female
## 1          0       32          0
## 2          0       53          0
## 3          0       10          0
## 4          0        3          0
## 5          0       11          0
## 6          0       50          0
## 7          0       10          0
## 8          0       30          0
## 9          0       10          0
## 10         0       25          0
## 11         0        7          0
## 12         0        5          0
## 13         3        3          0
## 14        15       15          0
## 15         7        7          0
## 16         8        8          0
## 17         0        0         36
## 18         0        0         66
## 19         0        0         16
## 20         0        0          4
## 21         0        0          9
## 22         0        0         34
## 23         0        0          7
## 24         0        0         64
## 25         0        0          5
## 26         0        0         29
## 27         0        0          7
## 28         0        0          5
## 29         2        0          2
## 30        14        0         14
## 31         7        0          7
## 32         8        0          8
D=mtcars; Dt() #データ例:mtcars
## Class: data.frame / Rows: 32 / Columns: 11
##  
##                   mpg  cyl disp  hp  drat wt    qsec  vs am gear carb
## Mazda RX4         21.0 6   160.0 110 3.90 2.620 16.46 0  1  4    4   
## Mazda RX4 Wag     21.0 6   160.0 110 3.90 2.875 17.02 0  1  4    4   
## Datsun 710        22.8 4   108.0  93 3.85 2.320 18.61 1  1  4    1   
## Hornet 4 Drive    21.4 6   258.0 110 3.08 3.215 19.44 1  0  3    1   
## Hornet Sportabout 18.7 8   360.0 175 3.15 3.440 17.02 0  0  3    2   
## Valiant           18.1 6   225.0 105 2.76 3.460 20.22 1  0  3    1   
## Duster 360        14.3 8   360.0 245 3.21 3.570 15.84 0  0  3    4   
## Merc 240D         24.4 4   146.7  62 3.69 3.190 20.00 1  0  4    2   
## Merc 230          22.8 4   140.8  95 3.92 3.150 22.90 1  0  4    2   
## Merc 280          19.2 6   167.6 123 3.92 3.440 18.30 1  0  4    4
D=Dat(c='v,a,m'); Dt() #列選択
## Class: data.frame / Rows: 32 / Columns: 3
##  
##                   vs am mpg 
## Mazda RX4         0  1  21.0
## Mazda RX4 Wag     0  1  21.0
## Datsun 710        1  1  22.8
## Hornet 4 Drive    1  0  21.4
## Hornet Sportabout 0  0  18.7
## Valiant           1  0  18.1
## Duster 360        0  0  14.3
## Merc 240D         1  0  24.4
## Merc 230          1  0  22.8
## Merc 280          1  0  19.2
D=ReplaceCol(D,'vs','0=>V-shaped,1=>Straight'); Dt(D) #列置換: 'vs' 
## Class: data.frame / Rows: 32 / Columns: 3
##  
##                   vs       am mpg 
## Mazda RX4         V-shaped 1  21.0
## Mazda RX4 Wag     V-shaped 1  21.0
## Datsun 710        Straight 1  22.8
## Hornet 4 Drive    Straight 0  21.4
## Hornet Sportabout V-shaped 0  18.7
## Valiant           Straight 0  18.1
## Duster 360        V-shaped 0  14.3
## Merc 240D         Straight 0  24.4
## Merc 230          Straight 0  22.8
## Merc 280          Straight 0  19.2
D=ReplaceCol(D,'am','0=>Automatic,1=>Manual') ; Dt(D) #列置換: 'am'
## Class: data.frame / Rows: 32 / Columns: 3
##  
##                   vs       am        mpg 
## Mazda RX4         V-shaped Manual    21.0
## Mazda RX4 Wag     V-shaped Manual    21.0
## Datsun 710        Straight Manual    22.8
## Hornet 4 Drive    Straight Automatic 21.4
## Hornet Sportabout V-shaped Automatic 18.7
## Valiant           Straight Automatic 18.1
## Duster 360        V-shaped Automatic 14.3
## Merc 240D         Straight Automatic 24.4
## Merc 230          Straight Automatic 22.8
## Merc 280          Straight Automatic 19.2
Cross(D,x=1,v=2) #個数
##          Automatic Manual
## Straight         7      7
## V-shaped        12      6
Cross(D,x=1,v=2,n=3) #和
##          Automatic Manual
## Straight       145    199
## V-shaped       181    118
Cross(D,x=1,v=2,n=3,m=T) #m=T平均
##          Automatic Manual
## Straight        21     28
## V-shaped        15     20
Cross(D,x=1,v=2,n=3,m=T,d=1) #d=1小数桁=1
##          Automatic Manual
## Straight      20.7   28.4
## V-shaped      15.0   19.8
D=Titanic; Dt() #データ:Titanic
## Class: table / Rows: 4 / Columns: 2
##  
##    Class Sex    Age   Survived Freq
## 1  1st   Male   Child No         0 
## 2  2nd   Male   Child No         0 
## 3  3rd   Male   Child No        35 
## 4  Crew  Male   Child No         0 
## 5  1st   Female Child No         0 
## 6  2nd   Female Child No         0 
## 7  3rd   Female Child No        17 
## 8  Crew  Female Child No         0 
## 9  1st   Male   Adult No       118 
## 10 2nd   Male   Adult No       154
Cross(x=1,v=4,n='F') #クロス集計(1:Class,4:Survived)
##       No Yes
## 1st  122 203
## 2nd  167 118
## 3rd  528 178
## Crew 673 212

—–

参考

トップページ

(東京大学 上田博人 Hiroto Ueda, 2022)