I want to adjust val column so that there will not be any negative values.

Ajusting rule is, 

* replace negative value with half of previous row
* do this for each hier ( group\_by(hier) )
* if more than one negative values consecutive, divide previous adjusted value to 2

```
xdat <- data.frame( 
  hier = c(rep("A",5), rep("B",5) )
  , val = c(4, 7, -3, 10, 5, 1, -7, -4, 5, 7)
           )

hier |  val | val_adjust
A    |  4   |    4
A    |  7   |    7
A    |  -3  |    3.5
A    |  10  |    10
A    |  5   |    5
B    |  1   |    1
B    |  -7  |    0.5
B    |  -4  |    0.25
B    |  5   |    5
B    |  7   |    7

```