Calculate group mean (or other summary stats) and assign to original data

前端 未结 4 1413
自闭症患者
自闭症患者 2020-11-21 10:15

I want to calculate mean (or any other summary statistics of length one, e.g. min, max, length, sum) of a nu

4条回答
  •  庸人自扰
    2020-11-21 10:32

    Have a look at the ave function. Something like

    df$grp.mean.values <- ave(df$value, df$group)
    

    If you want to use ave to calculate something else per group, you need to specify FUN = your-desired-function, e.g. FUN = min:

    df$grp.min <- ave(df$value, df$group, FUN = min)
    

提交回复
热议问题