I have a datasets of forest stands, each containing several tree layers of different age and volume.
I want to classify the stands as `even-` or `uneven-aged`, combining volume and age data. The forest is considered `even-aged` if more then 80% of the volume is allocated to age classes within 20 years apart. **I wonder how to implement the 'within 20 years apart' condition**? I can easily calculate the sum of volume and it's share for individual tree layers (`strat`). But how to check for 'how many years they are apart?' Is it some sort of moving window?

Dummy example:

```
# investigate volume by age classes?
library(dplyr)

df <- data.frame(stand = c("id1", "id1", "id1", "id1", 
                       'id2', 'id2', 'id2'),
             strat = c(1,2,3,4,
                       1,2,3),
             v = c(4,10,15,20,
                   11,15,18),
             age = c(5,10,65,80,
                     10,15,20))

# even age  = if more of teh 80% of volume is allocated in layers in 20 years range
df %>% 
  group_by(stand) %>% 
  mutate(V_tot = sum(v)) %>% 
  mutate(V_share = v/V_tot*100)

```

Expected outcome:

```
  stand strat     v   age V_tot V_share quality
  <fct> <dbl> <dbl> <dbl> <dbl>   <dbl>
1 id1       1     4     5    49    8.16 uneven-aged
2 id1       2    10    10    49   20.4  uneven-aged
3 id1       3    15    65    49   30.6  uneven-aged
4 id1       4    20    80    49   40.8  uneven-aged #* because age classes 65 and 80, even less then 20 years apart have only 70% of total volume
5 id2       1    11    10    44   25    even-aged
6 id2       2    15    15    44   34.1  even-aged
7 id2       3    18    20    44   40.9  even-aged

```