Considering this sample data, how do I round the values to whole numbers but the condition is that the values across each row should sum up to 971? While I simply can round the values using round()
, the total of the values across each row will not exactly sum up to 971.
df <- data.frame(A = c(728.25, 679.70, 631.15),
B = c(48.55, 97.10, 145.65),
C = c(48.55, 48.55, 48.55),
D = c(48.55, 48.55, 48.55),
E = c(48.55, 48.55, 48.55),
F = c(48.55, 48.55, 48.55))
There is a related thread on how to round percentages to 100% but not exactly sure how do I translate this when my goal is to derive a specific value for the total.
Similarly, I also tried round_percent()
but it is basically doing the same thing of rounding percentages to 100%.