ddply for sum by group in R

后端 未结 2 2026
后悔当初
后悔当初 2020-12-02 23:30

I have a sample dataframe \"data\" as follows:

X            Y  Month   Year    income
2281205 228120  3   2011    1000
2281212 228121  9   2010    1100
22812         


        
2条回答
  •  一整个雨季
    2020-12-02 23:56

    I think the package dplyr is faster than plyr::ddply and more elegant.

    testData <- read.table(file = "clipboard",header = TRUE)
    require(dplyr)
    testData %>%
      group_by(Y) %>%
      summarise(total = sum(income),freq = n()) %>%
      filter(freq > 3)
    

提交回复
热议问题