I want a way to solve such a problem

Step-by-step explanation:
to solve this you must first understand the "mean" value of a data set or "distribution".
the mean value is simply the sum of all measured or reported values divided by the number of measurements or reports.
if several data points have the same measured value, then so be it. they are all counting.
and that is what was happening here. the value "2" for example appeared 5 times during the measurements or reports.
"4" occurred 8 times. and so forth.
that is what "frequency" means : how often did that value occur during the observed period of measurements or reports ?
so, how many data points are there ? meaning how many measurements or reports were done in total ?
well, the sum of all frequencies :
(5 + 8 + x + 6 + 3)
to calculate the mean value we could now simply add every value up like 2+2+2+2+2.
or we help ourselves by using multiplication as a shortcut :
(2×5 + 4×8 + 6×x + 8×6 + 10×3)
the mean value is then as explained at the beginning :
(2×5 + 4×8 + 6×x + 8×6 + 10×3) / (5 + 8 + x + 6 + 3) =
= (10 + 32 + 6x + 48 + 30) / (22 + x) =
= (120 + 6x) / (22 + x) = 5.625
120 + 6x = 5.625(22 + x) = 123.75 + 5.625x
-3.75 = -0.375x
3.75 = 0.375x
x = 10
the frequency of 6 was 10 to achieve the mean value of 5.625.
add on : so, the way to solve this as so many similar problems in other areas is to set the principle (including a variable) equal to an actual outcome, and then you solve for that variable.