I looked at other questions like this, this and this, but all these calculate the shortest distance to a line segment defined by two endpoints, whereas I've not been able to do the same but for a line defined by an intercept and a slope.
This is my data, which I plot and add a line that will always have an intercept of 0 and slope defined by the means of the two variables.
df <- data.frame(x = seq(1, 10, 1),
y = seq(1, 10, 2),
id = head(letters, 10))
plot(df$x, df$y,
abline(a = 0, b = (mean(df$x) / mean(df$y))))
I am trying to calculate the shortest distance from each point to the line.