Frequency count of two column in R

后端 未结 7 950
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-27 03:37

I have two columns in data frame

2010  1
2010  1
2010  2
2010  2
2010  3
2011  1
2011  2

I want to count frequency of both columns and get

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-27 03:52

    If your data is dataframe df with columns y and m

    library(plyr)
    counts <- ddply(df, .(df$y, df$m), nrow)
    names(counts) <- c("y", "m", "Freq")
    

提交回复
热议问题