Name columns within aggregate in R

前端 未结 4 1794
逝去的感伤
逝去的感伤 2020-12-13 06:02

I know I can *re*name columns after I aggregate the data:

blubb <- aggregate(dat$two ~ dat$one, ...)
colnames(blubb) <- c(\"One\", \"Two\")
         


        
4条回答
  •  抹茶落季
    2020-12-13 06:24

    The answer to your first question is yes. You can certainly include the column names in the aggregate function. Using the names from your example above:

    blubb <- aggregate(dat,list(One=dat$One,Two=dat$Two),sum)

    I like the part about possibly pulling in the original column names automatically. If I figure it out I'll post it.

提交回复
热议问题