Getting the mean value for every Id in a data frame

后端 未结 5 1558
旧巷少年郎
旧巷少年郎 2021-01-21 06:06

Imagine I have a data frame with 2 columns

Id    Value
12    13
32    3
6022  11
9142  231
12    23
119   312
...

and I want to get the mean va

5条回答
  •  广开言路
    2021-01-21 07:08

    Just for completeness basic solution is tapply:

    tapply(data$Value, data$Id, mean)
    

    (or using with as with(data, tapply(Value, Id, mean)))

提交回复
热议问题