A quantum system has $r$ discrete energy levels $\varepsilon_1,\varepsilon_2,\varepsilon_3,...,\varepsilon_r$ and $N$ particles distributed in these levels, with the number of particles at each level denoted by $n_1,n_2,n_3,...,n_r$. I'm trying to find the average number of particles in the $i$-th energy level, $\left\langle n_i\right\rangle$, and the fluctuation of this average, $\left\langle(\Delta n_i)^{2}\right\rangle$, using the Canonical Ensemble.
My attempt
The average energy of the system at the state $R$ determined by the occupation numbers $(n_1,n_2,n_3,...,n_r)_R$ can be computed by
$$ \langle E\rangle=\left\langle E_{R}\right\rangle=\sum_{R} P_{R} E_{R} =\frac{1}{Z}\sum_{R} E_{R} e^{-\beta E_{R}} =-\frac{1}{Z}\bigg(\frac{\partial Z}{\partial \beta}\bigg)_{N, V} =-\bigg(\frac{\partial \ln Z }{\partial \beta}\bigg)_{N, V} $$
With a similar process, keeping in mind that $E_{R} = \sum_{r} n_r \varepsilon_{r}$, one gets that
$$\langle n_i\rangle = \sum_{R} P_{R} n_i =\frac{1}{Z}\sum_{R} n_r e^{-\beta \sum_{r} n_i \varepsilon_{r}} =-\frac{1}{\beta}\bigg(\frac{\partial \ln Z}{\partial \varepsilon_i}\bigg)_{N, V} $$
Which is supposed to be the correct result. However, I am not sure that this $\langle n_i \rangle = \sum_{R} P_{R} n_i$ is valid for this average since $P_r$ is the probability that the system is in the $R$-state, not that the $r$-th energy level has a certain number of particles...
Is the procedure I have performed in this correct?