Weighted Least Squares can be computed in R using the command lm() with the weights option. To understand the formula, I computed them manually too
lm()
weights