In my dataset, column A and B are strongly correlated and the scatter plot is as follows:
ggplot(df, aes(x = B, y =A)) + geom_point() + geom_smooth()
A is inversely proportional to B and forms a perfect nonlinear line.
Yet in column B, there are some missing values NA and I would like to replace them while keeping the perfect line instead of dropping them or replacing them by mean.
Here is my attempt to calculate the value directly but this approach doesn't work very well.
const = mean(transform(df, new = A* B)$new)
df$B[is.na(df$B)] <- const / df$A
Instead of calculating it, is there a way to do so? For example, how to replace the missing values with a predict() function ?
Thank you.

