Computing mean and sd from a frequency histogram (in R)

On page 4 of this document, there is a frequency distribution (histogram) of some students' math scores.

You can access the exact same info. shown on page 4 of this document below (in R).

Question: I was wondering how to compute the $$mean$$ and $$sd$$ of scores in this histogram?

I appreciate a possibly R solution.

(Note: My understanding is we can't simply take the $$mean$$ and $$sd$$ of scores from the histogram data.)

data <- read.csv('https://raw.githubusercontent.com/rnorouzian/e/master/6grade.csv')

# 3 first rows of the histogram data:

#    score  freq cum.freq pct. cum.pct
# 1   1038   142      142 0.04    0.04
# 2   1171    15      157 0.00    0.04
# 3   1250    78      235 0.02    0.06


Since the 'scores' are not equally spaced they probably aren't the bin midpoints, so we can hope they are the bin means

The mean is the weighted mean of the score

wmean <- sum(score*freq)/sum(freq)


To get the variance, take the weighted variance

sum( (score-wmean)^2*freq)/sum(freq)


(then square root to get the standard deviation)

If the scores were the bin midpoints this variance would be a slight overestimate and could be improved using Sheppard's correction