I'm trying to use dplyr to calculate grouped correlations, but something is clearly wrong since the code below works only in the console:
require(dplyr)
set.seed(123)
xx = data.frame(group = rep(1:4, 100), a = rnorm(400) , b = rnorm(400))
gp = group_by(xx, group)
summarize(gp, cor(a, b))
  group   cor(a, b)
1     1 -0.02073084
2     2  0.12803353
3     3  0.06236264
4     4 -0.06181904
If i use the same code in RStudio, i get:
   cor(a, b)
1 0.02739193
What's happening?