How can I replace the values of a df which contains NA values, to the percentage of the contribution to the sum of the row?
Example:
# dummy df
a <- c("x","y","z")
b <- c(10,5,2)
c <- c("NA",1,"NA")
d <- c("NA",4,8)
dummy <- data.frame(a,b,c,d)
a | b | c | |
---|---|---|---|
x | 10 | NA | NA |
y | 5 | 1 | 4 |
z | 2 | NA | 8 |
What I want:
a | b | c | |
---|---|---|---|
x | 100% | NA | NA |
y | 50% | 10% | 40% |
z | 20% | NA | 80% |