Put $f\left( \mathbb{R} \right) = U \ne \emptyset $, then $\forall y \in U$, we have $f\left( y \right) = y$ by $f\left( {f\left( x \right)} \right) = f\left( x \right)$. We can call $U$ a collection of fixed points of $f$.
If a funtion $g$ maps $\mathbb{R}-U$ to $U$, then it satisfies $g\left( {g\left( x \right)} \right) = g\left( x \right)$.
For example, $f\left( x \right) = \left| x \right|$, we get $U = \left[ {0, + \infty } \right)$, luckily, $f$ maps $\left( { - \infty ,0} \right)$ to $U$.
And, if $U$ has exactly one (fixed) point, say $c$, i.e. $f(c)=c$, then $f$ must maps $\left( { - \infty ,\infty } \right) - \left\{ c \right\}$ to $\{c\}$. That is, $f$ is a constant value function.