lundi 13 février 2017

Calculation by group in one column R

Vote count: 0

group=c("A","A","B","A","B","C","C","A")
y=c(3,4,5,2,1,4,1,2)
df=data.frame(group,y)

using aggregate, I can get the average by

aggregate(df$y, list(df$group), mean)

But my question is: How to do something like : (y_ij-mean_i) where mean_i is the average for group i

thank you.

asked 19 secs ago

Let's block ads! (Why?)



Calculation by group in one column R

Aucun commentaire:

Enregistrer un commentaire