A sample data first

```
        set.seed(123) 
        dat <- tibble(x = sample(-10:10, size = 11,replace = T))

        # A tibble: 11 x 1
              x
            <int>
        1    -4
        2     6
        3    -2
        4     8
        5     9
        6   -10
        7     1
        8     8
        9     1
        10    -1
        11    10

```

I have a variable y with initial value of 2. I want to calculate the final value of y by adding `x` to y in a given time step using:

```
      y[i] = y[i-1] + x[i]    

     dat %>% mutate(y = accumulate(x, ~ .x + .y, .init = 2)[-1])

            # A tibble: 11 x 2
                  x     y
                <int> <dbl>
            1    -4    -2
            2     6     4
            3    -2     2
            4     8    10
            5     9    19
            6   -10     9
            7     1    10
            8     8    18
            9     1    19
            10    -1    18
            11    10    28    

```

Howevr, the condition that I want to impose is that in a given time step, y cannot be > 10 or be negative. If y > 10, 10 and if y < 0, 0. Therefore, the actual
y (shown in y1 below) should be:

```
          # A tibble: 11 x 2
                  x     y    y1
                  <int> <dbl>
            1    -4    -2      0 (-2 converted to 0)
            2     6     4      6 
            3    -2     2      4
            4     8    10     10 (12 converted to 10)
            5     9    19     10 (19 converted to 10)
            6   -10     9      0  
            7     1    10      1
            8     8    18      9  
            9     1    19     10
            10    -1    18     9
            11    10    28    10  (19 converte to 10)

```