smalldat <- data.frame(group1 = rep(1:2, c(5,5)),
group2 = rep(c("a","b"), 5),
x = rnorm(10))
smalldat
# group1 group2 x
# 1 1 a -1.2173399
# 2 1 b 0.2601609
# 3 1 a -1.9955389
# 4 1 b -0.7949134
# 5 1 a 0.9655160
# 6 2 b -1.2307946
# 7 2 a 0.3562118
# 8 2 b 0.7674343
# 9 2 a -0.2472418
# 10 2 b -1.2653220
a<-group_by(smalldat,group1)
summarize(a,mm=mean(x))
# mm
# 1 -0.1690133
so, why do i get the mean of all x, instead of the mean of 1 and 2? Thank you