I want to compute group means of a variable but excluding the focal respondent: 

```
set.seed(1)
dat <- data.table(id = 1:30, y = runif(30), grp = rep(1:3, each=10))

```

The first record (respondent) should have an average of... the second... and so on:

```
mean(dat[c==1, y][-1])
mean(dat[c==1, y][-2])
mean(dat[c==1, y][-3])

```

For the second group the same: 

```
mean(dat[c==2, y][-1])
mean(dat[c==2, y][-2])
mean(dat[c==2, y][-3])

```

I tried this, but it didn't work:

```
ex[, avg := mean(ex[, y][-.I]), by=grp]

```

Any ideas?