Let $ (X,\Sigma,\mu)$ be a finite measure space. ($\mu(X)<\infty$). Let $f \in L^1(\mu)$ be a complex-valued function, and let $S \subseteq C$ be a non-closed subset.
Suppose that for every $E \in \Sigma$, $\frac{1}{\mu(E)}\int_E fd\mu \in S $.
Is it true that $f(x) \in S$ almost everywhere?
I know this is true if $S$ is closed (this is theorem 1.40 in "Real and complex analysis" by Rudin). I am looking for counter-examples when $S$ is not closed.
Take $f=e^{it}$ on $X=[0,1]$ with $\mu$ the Lebesgue measure so that $\frac 1{\mu(E)}\chi_E f \in L^1$ whenever $\mu(E)>0$ and $$\left|\frac 1{\mu(E)}\int_E f \right|\le \frac 1{\mu(E)}\int_E |e^{it}|=1$$ If this inequality is not strict, by Thm 1.39c) in Rudin's book, there exists a constant $\alpha$ s.t. $\alpha\frac 1{\mu(E)}\chi_E f =\frac 1{\mu(E)}\chi_E$ on a set $C$ with $\mu(C^c)=0$. Thus $\alpha = e^{-it}$ whenever $t\in E\cap C$. But $\mu(E\cap C)=\mu(E)$ implies $E\cap C$ has more than 2 elements and $1/f$ is injective so $\alpha$ cannot be constant, a contradiction that forces $A_E(f)\in B(0,1)$ for all $E$ with positive measure even though $f(X)\subset B(0,1)^c$.