renaming the output column with the plyr package in R

前端 未结 2 1200
感动是毒
感动是毒 2020-12-31 11:16

Hadley turned me on to the plyr package and I find myself using it all the time to do \'group by\' sort of stuff. But I find myself having to always rename the resulting col

相关标签:
2条回答
  • 2020-12-31 11:40

    This seems to work:

    > groupAcres <- ddply(mydata, c("state"), function(df) c(myName=sum(df$acres)))
    > groupAcres
      state   myName
    1     A 56.87973
    2     B 57.84451
    3     C 52.82415
    
    0 讨论(0)
  • 2020-12-31 11:54

    Use summarise (or summarize):

      groupAcres <- ddply(mydata, "state", summarise, 
         myName = sum(acres))
    
    0 讨论(0)
提交回复
热议问题