-1

I am getting an overall mean value for my dataset whereas I would like it per repName

Here is a dataset example

repName divergence
L2a 0.013
L2a 0.114
L2a 0.294
L2a 0.338
L2b 0.284
L2b 0.306
MIR 0.282
MIR 0.242
MIR 0.181
MIR3    0.235
MIR3    0.23
MIR3    0.346
MIR3    0.331
MIR3    0.279
MIR3    0.303
MIR3    0.095

Here is the dataset I want

repName divergence
L2a 0.18975
MIR3    0.259857143
L2b 0.295
MIR 0.235

and here is my attempt at the code

library(dplyr)
GroupedTableProportion <- mydiv %>% group_by(repName) %>% summarise(divergence)

but this just gives me

mean(divergence)
0.1887634
Sebastian Zeki
  • 6,690
  • 11
  • 60
  • 125

2 Answers2

1

You need to tell summarise what to do

mydiv %>% group_by(repName) %>% summarise(mean(divergence))
Thierry
  • 18,049
  • 5
  • 48
  • 66
0

Other options include aggregate from base R

aggregate(divergence~repName, mydiv, mean)

Or using data.table

library(data.table)
setDT(mydiv)[, list(divergence=mean(divergence)), by = repName]
akrun
  • 874,273
  • 37
  • 540
  • 662