I am pretty new to R and I have a loop which gives sometimes a matrix like this:

```
        1 2
  FALSE 0 0
  TRUE  0 2

```

I need to do as follows:
If the two cells in a single row have zeros replace them by 0.5
If one of the cells is not zero divide by the sum of the row 

so the result of this will be:

```
         1    2
  FALSE 0.5 0.5
  TRUE  0    1

```

Any idea please?
Thank you