-3

here is my dataframe

I would like to fid the % of each row

       a     b     c
1      NA    10    10
2      NA    11    13
3      NA    20    12
4      NA    20    20
5      NA     3    15
6      10     2     8

first I sum the first row 10+10=20 so the % of the first row is 50% for b and 50% for c It should looks like this

       a     b     c
1      NA    0.5   0.5
2      NA  0.458 0.542
3      NA  0.625 0.372
4      NA    0.5   0.5
5      NA  0.166 0.834
6     0.5    0.1   0.4

Thanks

1 Answers1

-1

If df is your data.frame:

apply(df, 1, function(x) x/sum(x, na.rm = TRUE))