Create summary table of categorical variables of different lengths

后端 未结 6 640
伪装坚强ぢ
伪装坚强ぢ 2021-01-02 11:04

In SPSS it is fairly easy to create a summary table of categorical variables using \"Custom Tables\":

\"This

6条回答
  •  耶瑟儿~
    2021-01-02 11:27

    Here is a solution using the freq function of the questionr package (shameless autopromotion, sorry) :

    R> lapply(df, freq)
    $vs
        n    %
    0  18 56.2
    1  14 43.8
    NA  0  0.0
    
    $am
        n    %
    0  19 59.4
    1  13 40.6
    NA  0  0.0
    
    $gear
        n    %
    3  15 46.9
    4  12 37.5
    5   5 15.6
    NA  0  0.0
    
    $carb
        n    %
    1   7 21.9
    2  10 31.2
    3   3  9.4
    4  10 31.2
    6   1  3.1
    8   1  3.1
    NA  0  0.0
    

提交回复
热议问题