Get group mean with multiple grouping variables and excluding own group value
问题 I'm looking for a faster way to calculate a group mean with multiple grouping variables while excluding own group values. A thought experiment would be finding average value (e.g. price) for a county from the counties in the same state in the same year excluding own county's value. Here's a toy data set. df <- data_frame( state = rep(c("AL", "CA"), each = 6), county = rep(letters[1:6], each = 2), year = rep(c(2011:2012), 6), value = sample.int(100, 12) ) df %>% group_by(state, county, year) %