I am working with a data recently, part of it showed as followed.

```
    SID1A   day1    day2    pci TRTREG1C    ladcc
1   1000_00001  0   1   0   A   98
2   1000_00001  1   2   0   A   95
3   1000_00001  2   3   0   A   94
4   1000_00001  3   4   0   A   99
5   1000_00001  4   5   0   A   97
6   1000_00002  0   1   0   B   98
7   1000_00002  1   2   0   B   94
8   1000_00002  2   3   0   B   97
9   1000_00002  3   4   0   B   96
10  1000_00003  0   1   0   A   101
11  1000_00003  1   2   0   A   99
12  1000_00004  0   1   0   B   89
13  1000_00004  1   2   0   B   88

```

What I am trying to get is the roll mean of ladcc by SID1A by the width of 3. So I tried the function rollmean from zoo and expression from dplyr. 

```
    dt <- dt %>% group_by(SID1A)%>% 
          mutate(adcc_av3 = rollmean(x=ladcc, min(3, length(ladcc)), partial = T, 
          na.pad = T, fill=NA, align = 'right'))

```

It gives me result as followed. 

```
   SID1A    day1    day2    pci TRTREG1C    ladcc   adcc_av30
1   1000_00001  0   1   0   A   98  NA
2   1000_00001  1   2   0   A   95  NA
3   1000_00001  2   3   0   A   94  95.66666667
4   1000_00001  3   4   0   A   99  96
5   1000_00001  4   5   0   A   97  96.66666667
6   1000_00002  0   1   0   B   98  NA
7   1000_00002  1   2   0   B   94  NA
8   1000_00002  2   3   0   B   97  96.33333333
9   1000_00002  3   4   0   B   96  95.66666667
10  1000_00003  0   1   0   A   101 NA
11  1000_00003  1   2   0   A   99  100
12  1000_00004  0   1   0   B   89  NA
13  1000_00004  1   2   0   B   88  88.5

```

What I want from the result is 

```
   SID1A    day1    day2    pci TRTREG1C    ladcc   adcc_av30
1   1000_00001  0   1   0   A   98  98
2   1000_00001  1   2   0   A   95  96.5
3   1000_00001  2   3   0   A   94  95.66666667
4   1000_00001  3   4   0   A   99  96
5   1000_00001  4   5   0   A   97  96.66666667
6   1000_00002  0   1   0   B   98  98
7   1000_00002  1   2   0   B   94  96
8   1000_00002  2   3   0   B   97  96.33333333
9   1000_00002  3   4   0   B   96  95.66666667
10  1000_00003  0   1   0   A   101 101
11  1000_00003  1   2   0   A   99  100
12  1000_00004  0   1   0   B   89  89
13  1000_00004  1   2   0   B   88  88.5

```

Which is `rollmean(ladcc, k = min(3, **number of rows before this row**))`, I tried `rollmean(ladcc, k = min(3, day2))`, but it don't work and gave me error of "k <= n is not true". So the manipulation of data in dplyr is not performed row by row? Thank you very much in advance.