You can use prop.table
:
prop.table(m, 1)
d1 d2 d3 d4 d5 d6 d7
d1 0.0000000 0.0 1.0000000 0.0000000 0.0000000 0.0 0.0000000
d2 0.0000000 0.5 0.5000000 0.0000000 0.0000000 0.0 0.0000000
d3 0.3333333 0.0 0.3333333 0.3333333 0.0000000 0.0 0.0000000
d4 0.0000000 0.0 0.0000000 0.5000000 0.5000000 0.0 0.0000000
d5 0.0000000 0.0 0.0000000 0.0000000 0.0000000 0.0 1.0000000
d6 0.0000000 0.0 0.0000000 0.0000000 0.0000000 0.5 0.5000000
d7 0.0000000 0.0 0.0000000 0.3333333 0.3333333 0.0 0.3333333
Here, the argument 1
means that the function is applied to each row separately.