Let $d(n)$ be the number of positive integers that divide $n$. It is well known that $d(n)$ is on average $\log n$. However, it is also well known that for most $n$ the number $d(n)$ is rather close to $(\log n)^{\log 2}$. What explains the anomaly is that the values of $d(n)$ that are larger than its typical value are typically way larger, hence, they dominate the first moment. The average of $d^2(n)$ is $\gg (\log n)^3$, which is just another manifestation of the same anomaly.
To understand these things a little better I was interested in estimating the average $$ R(x):= \sum_{1\leq n \leq x } | d(n)-\log n|.$$ Has anyone seen an asymptotic for this in the literature?
As Alexander Kalmynin wrote in the comments one has $$R(x)=\sum_{1\leq n \leq x } |d(n)-\log n| \ll \sum_{n\leq x } d(n) +x\log x\ll x\log x .$$ Furthermore, for each $\epsilon>0$ there exists a subset $A_\epsilon\subset \mathbb N$ of density $1$ with $d(n)\leq (\log n)^{\log 2+\epsilon}$ for all $n\in A_\epsilon$, we get $$ R(x) \geq \sum_{n\in A_\epsilon\cap[1,x]} ((\log n)- (\log n)^{9/10}) \gg x \log x.$$ Hence, $$ x\log x\ll R(x) \ll x \log x.$$