If $F$ is a finite set and $f:F\to\mathbb{R}$ is a function, we can take its average as $1/N \sum_{x\in F}f(x)$, where $N$ is the number of elements of $F$. The average of a finite set $F$ of real numbers is simply the average of the identity on $F$.
If we want to extend this to a nonnegative function $f:X\to\mathbb{R}$ with $X$ an infinite set, we encounter two problems. First, since the cardinality of $X$ is not a real number, it is not clear what dividing by that number means. Second, if $X$ is uncountable and $f(x)\neq 0$ for uncountably many $x$, the sum $\sum_{x\in X}f(x)$ is necessarily infinite. If $f$ is not nonnegative, we can in addition get problems with convergence of the sum.
In order to solve the first problem, we observe that we can sometimes use a different notion of size for the underlying set $N$. For eaxample, a closed interval $[a,b]$ is necessarily uncountable if $aLebesgue measure.
To deal with the second problem, we can ask ourselves what a good alternative to adding up might be. If $f$ is constant with value $c$ on the interval $[a,b]$ and zero everywhere else, we would want that "replacement of sum"$/$"size of $[a,b]$"$=$ "replacement of sum"$/(b-a)=c$. So "replacement of sum"$=c(b-a)$. Now the sum of the values of $f+g$ is in the finite case the sum of the values of $f$ plus the sum of the values of $g$. Also, the sum of the values of $\alpha f$ equals the sum of the values of $f$ times $\alpha$ when $\alpha$ is a real number. So we can sum up functions that are linear combinations of "blocks". Extending this by a limiting operation to a wider class of functions gives us the integral as a replacement of summation.