Frequency of values per column in table

前端 未结 4 1036
傲寒
傲寒 2020-12-21 07:59

What is a good way to get the independent frequency counts of multiple columns using dplyr? I want to go from a table of values:

# A tibble: 7          


        
4条回答
  •  天涯浪人
    2020-12-21 08:38

    Using tabulate in base R:

    apply(df,2,function(x) tabulate(x)[min(df):max(df)])
    
    #     a  b c  d
    #[1,] 2  0 2  1
    #[2,] 1  4 2  0
    #[3,] 2  2 0  6
    #[4,] 0  1 2 NA
    #[5,] 2 NA 1 NA
    

提交回复
热议问题