Let $N$ be the number of molecules of a given gas. If each molecule has $f$ degrees of freedom,then according to the law of equipartition of energy,the internal energy associated with each degree of freedom is $\frac{1}{2} k_{B} T$.
The total internal energy $U$ of the gas is given by:
$U = [\text{Total number of molecules}] \times [\text{Degrees of freedom per molecule}] \times [\text{Internal energy per degree of freedom}]$
$\therefore U = N \times f \times \frac{1}{2} k_{B} T$
Since $N = \mu N_{A}$,where $\mu$ is the number of moles and $N_{A}$ is Avogadro's number:
$U = \mu N_{A} \times f \times \frac{1}{2} k_{B} T$
Using the relation $R = N_{A} k_{B}$:
$U = \mu f \left( N_{A} k_{B} \right) \frac{1}{2} T$
$\therefore U = \frac{1}{2} \mu f RT$