I've got a dataset where there are some NA's but I can manually work out what the values should be as the df is a column for name and the rest of the columns are just numbers followed by a final column with total. Only one NA appears per row at most so I can work out what the value should be by using the total column and the sum of all the other columns. Just wondering what would be the best way to fill these NA's without having to hardcode one by one as the df I'm using is pretty big
example df:
df = structure(list(city = c("sydney", "new york", "london", "beijing", "paris", "madrid"),
year = c(2005:2010),
A = c(1, 4, 5 , NA, 2, 1),
B = c(3, NA, 4 , 9, 0, 6),
C = c(3, 4 , 6, 1, 8, NA),
total = c(NA, 10, 15, 14, NA, 15)),
class = "data.frame", row.names = c(NA, -6L))
df