$f$ locally (Lebesgue) integrable function on real line, $g(x):= \lim _{r\to \infty} \frac 1r \int_{x-r}^{x+r} f(t) dt$ exists for every real $x$ Let $f : \mathbb R \to \mathbb R$ be a function such that $f \in L^1[-a,a] , \forall a \in (0,\infty)$ and $g(x) : = \lim _{r\to \infty} \dfrac 1r \int_{x-r}^{x+r} f(t) dt$ exists in $\mathbb R$ for every $x \in \mathbb R$ . Then is it true that $g$ is an affine map i.e. $g(x)-g(0)=x(g(1)- g (0)) , \forall x \in \mathbb R$ ?
 A: The answer is yes. 
Let $\int_a^b:=\int_a^b f(t) dt$, with $\int_b^a:=-\int_a^b$ (if $a<b$). We have
\begin{equation}
 \int_{x-r}^{x+r}\sim rg(x)\tag{*}
\end{equation}
as $r\to\infty$, where $A\sim B$ is understood as $A-B=o(r)$, and $x,y,\dots$ are any real numbers. Hence, substituting $s:=r-x$, we have 
\begin{equation}
 \int_{-s}^{2x+s}\sim rg(x)\sim sg(x) 
\end{equation}
as $s\to\infty$. Comparing this with 
\begin{equation}
 \int_{-s}^{s}\sim sg(0), 
\end{equation}
we have 
\begin{equation}
 \int_{s}^{2x+s}\sim s(g(x)-g(0)) 
\end{equation}
for $s\to\infty$ -- and then similarly for $s\to-\infty$. 
Hence, 
\begin{equation}
 \int_{y-r}^{y+r}-\int_{x-r}^{x+r}=\int_{x+r}^{y+r}-\int_{x-r}^{y-r}
 \sim2r(g(\tfrac{y-x}2)-g(0))
\end{equation}
as $r\to\infty$. 
Also, by $(*)$, 
\begin{equation}
 \int_{y-r}^{y+r}-\int_{x-r}^{x+r}
 \sim r(g(y)-g(x)). 
\end{equation}
So, 
\begin{equation}
 g(y)-g(x)=2[g(\tfrac{y-x}2)-g(0)] \tag{**}
\end{equation}
for all real $x,y$. Since $g$ is measurable, this implies that it is affine -- see details in the edit below. 
Edit: Willie Wong offered a strengthening of the above argument, which yields the Cauchy functional equation, from which the result easily follows. 
I would like to show how to use just the functional equation $(**)$ to get the same result. 
The reasoning is quite similar to that for the Cauchy functional equation; cf. this. 
Indeed, rewrite $(**)$ as 
\begin{equation}
 h(y)-h(x)=2h(\tfrac{y-x}2) \tag{***}
\end{equation}
for all real $x,y$, where $h:=g-g(0)$. 
Since $h(0)=0$ and $h(y)-h(x)$ depends on $x$ and $y$ only via $y-x$, it easily follows that $h(x)=h(1)x$ for all rational $x$. 
It remains to show that $h$ is continuous. In view of $(***)$, it is enough to verify that $h$ is continuous at $0$. Take any neighborhood $U$ of $0$, and then let $V$ be any neighborhood of $0$ such that $\frac12\,(V-V)\subseteq U$. The union of the sets $h^{-1}(x+V)$ over all rational $x$ is $\mathbb R$. So, for some rational $q$ the set $W:=h^{-1}(q+V)$ is of positive Lebesgue measure. Therefore, $W-W$ is a neighborhood of $0$. By $(***)$, 
for any $x,y$ in $W$, we have $h(\tfrac{y-x}2)=\frac12\,(h(y)-h(x))\in\frac12\,[(q+V)-(q+V)]=\frac12\,(V-V)\subseteq U$, so that 
$h(\frac12\,(W-W))\subseteq U$. Since $W-W$ is a neighborhood of $0$, the result follows. 
A: No, consider the function which takes the value 0 for negative x, and the value 1 for non-negativ x.
