Topological spaces admitting an averaging function Let $M$ be a topological space. Define an averaging function as a continuous map $f:M \times M \to M$ which satisfies $f(a,b) = f(b,a)$ for all $a,b \in M$ and $f(a,a) = a$ for all $a \in M$.
These seem like reasonable properties for a function which deserves the name "average" to have, since they are enjoyed by the usual averaging functions on $\mathbb{R}^n$.  
One can rule out an averaging function on both $S^1$ and $S^2$ by some cohomological arguments.  I have not worked out whether any sphere admits an averaging function, but I suspect not.  
Euclidean spaces all do (given by the usual average). 
Does anyone have a characterization of spaces which admit an averaging function? 
 A: Here is a proof that no sphere (of dimension $>0$) admits an averaging function.  Suppose there is an averaging function $f:S^n\times S^n\to S^n$.  Let $T(x_0,x_1,x_2,\dots,x_n)=(-x_0,-x_1,x_2,\dots,x_n)$; then $T:S^n\to S^n$ is homotopic to the identity and satisfies $T(T(x))=x$.   Now consider the map $g:S^n\to S^n$ given by $g(x)=f(x,T(x))$.  Since $T$ is homotopic to the identity, $g$ is homotopic to $x\mapsto f(x,x)=x$, and so $g$ has degree $1$.  But note that $$g(T(x))=f(T(x),T(T(x)))=f(T(x),x)=f(x,T(x))=g(x),$$ so $g$ factors through the quotient $S^n\to S^n/{\sim}$, where $\sim$ identifies $x$ with $T(x)$.  It is easy to see that $S^n/{\sim}\cong S^n$ and the quotient map has degree $2$.  Thus $g$ must have even degree, which is a contradiction.
On the other hand, here are some spaces that have means.  First, suppose $M=|X|$ is the geometric realization of a countable contractible simplicial set.  The functor $X\mapsto X\times X/\Sigma_2$ commutes with geometric realization for countable simplicial sets, so we get a CW-complex structure on $M\times M/\Sigma_2$ such that the diagonal $M\to M\times M/\Sigma_2$ is a subcomplex.  Since $M$ is contractible, it follows by obstruction theory that $M$ is a retract of $M\times M/\Sigma_2$.  But such a retraction is exactly a mean on $M$.  (The restriction to countable simplicial sets is just so that the product has the right topology; if you work in the category of compactly generated spaces rather than all spaces, you can remove the countability hypothesis.  I also suspect that this argument works for arbitrary contractible CW-complexes (not just realizations of simplicial sets), but in that case it is not obvious how to get a CW-structure on $M\times M/\Sigma_2$ with the diagonal as a subcomplex).
There are also some spaces with means with more interesting homotopical properties.  For instance, let $(A_n)_{n\geq 0}$ be a sequence of countable $\mathbb{Z}[1/2]$-modules (as above, the countability hypothesis can be dropped if you work with compactly generated spaces).  Consider the bounded chain complex of $\mathbb{Z}[1/2]$-modules whose objects are the $A_n$ and whose maps are all zero.  Via the Dold-Kan correspondence, we obtain from this chain complex a countable simplicial $\mathbb{Z}[1/2]$-module $X$ such that $\pi_n(X)=A_n$.  The geometric realization $M=|X|$ is then a topological $\mathbb{Z}[1/2]$-module with $\pi_n(M)=A_n$.  We can then define a mean on $M$ by $f(a,b)=(a+b)/2$.
A: Such functions are called means. The earliest paper on the subject that I’ve seen is G. Aumann, Über Räume mit Mittelbildungen, Mathematische Annalen (1943), Vol. 19, 210-215. He shows inter alia that no $S^k$ has a mean; that the only $2$-dimensional manifold with a mean is the open disk; and that if $X$ has a mean, then so does every retract and every component of $X$.
Three relatively recent papers that I was able to find fairly quickly:
Mirosław Sobolewski, Means on chainable continua, Proc. Amer. Math. Soc., Vol. 136, Nr. 10, October 2008, 3701-7, shows that a chainable continuum that admits a mean is homeomorphic to the interval.
T. Banakh, R. Bonnet, W. Kubiś, Means on scattered compacta, Topological Algebra and its Applications (2014), Vol. 2, Nr. 1, 5-10, construct a scattered compact space admitting no mean.
Section 6 of Janusz J. Charatonik, Selected problems in continuum theory, Topology Proceedings, Vol. 27, Nr. 1, 2003, 51-78, lists some known results and open questions concerning means on continua.
All have some references that may be of interest.
I’ve a faint recollection that in the 1970s or 1980s Jan van Mill or some of the Dutch topologists around him did some work on means, but I can’t at the moment locate any of it.
A: Edit:  This post has been edited to take Eric Wofsey's comments into account.  The end result is the following theorem:

Suppose $X$ is a closed manifold of positive dimension.  Then $X$ does NOT admit an averaging function.

If an averaging $f:X\times X\rightarrow X$ exists, it induces a map $f_\ast: \pi_k(X)\oplus \pi_k(X)\rightarrow \pi_k(X)$.
Observation 1:  $f_\ast(g,g) = g$.  Proof:  Consider the composition $X\rightarrow X\times X\rightarrow X$, where the first map is the diagonal embedding.  By assumption, this composition is the identity.  Now, apply functoriality.
Observation 2:  $f_\ast(g,h) = f_\ast(h,g)$.  Proof:  Consider the composition $X\times X\rightarrow X\times X\rightarrow X$ where the first map swaps the two factors and apply functoriality.
These two observations together have very strong consequences.  For example:
Corollary:  Suppose $G$ is a group with a homomorphism $f:  G\times G\rightarrow G$ satisfying both observations.  Then $G$ is abelian and every element of $G$ is twice another element of $G$.
Proof:  First we show that every element of $G$ is twice another, or, in multiplicative notation, that for any $g\in G$, $g = h^2$ for some $h\in G$.  In fact, setting $h = f(g,e)$, we see $h^2 = f(g,e)f(g,e) = f(g,e)f(e,g) = f(g,g) = g$.
Now we show that $G$ is abelian.  We have \begin{align*} [f(g,1)f(h,1)]^2 &= f(gh, 1)^2 \\ &= f(gh,1)f(1,gh) \\ &=f(gh,gh)\\ &= gh \\ &= f(g,1)^2 f(h,1)^2\end{align*} so $[f(g,1)f(h,1)]^2 = f(g,1)^2 f(h,1)^2$.  Writing these out an canceling, this reduces to $f(h,1)f(g,1) = f(g,1)f(h,1)$.  Replacing $h$ and $g$ with $h^2$ and $g^2$, this becomes $hg = gh$, so $G$ is abelian. $\square$
Now, it is easy to see that in a cyclic group, every element is twice another iff the group has odd order.  It follows that a finitely generated abelian groups for which every element is twice another is a direct sum of cyclic groups of odd order.  In particular, it is finite.
Theorem:  If $X^n$ is a closed manifold of positive dimension $n > 0$, then $X$ does not admit an averaging function.
Proof:  Since $X$ is closed, $\pi_1(X)$ is finitely generated, and hence finite for all $k$.  Since $\pi_k(X)$ is finitely generated as a $\pi_1(X)$ module, it follows that $\pi_k(X)$ is is finitely generated for all $k$.  Pass to the universal cover $\tilde{X}$, which is closed because $\pi_1(X)$ is finite.  By the Hurewicz Theorem mod $\mathcal{C}$), it follows that all the homology groups of $\tilde{X}$ are finite.  But, by Poincare duality, $H_n(\tilde{X})\cong \mathbb{Z}$.  This is a contradiction, unless $n = \dim X = 0$.  $\square$
These ideas can also be used to show that $\mathbb{R}^2$ is the only surface (no boundary) admitting an averaging function.
Sketch:  We have already ruled out closed manifolds, so we assume $X$ is a non-compact manifold.  Then, it is relatively well known that $X$ deformation retracts onto its $1$-skeleton.  If follows that $\pi_1(X;\mathbb{Z})$ is a free abelian group.  This contradicts the corollary, unless $\pi_1(X;\mathbb{Z})$ is trivial.  This, in turn implies that $X$ deformation retracts onto its $0$-skeleton, that is $X$ is contractible.  This implies $X$ is homeomorphic to $\mathbb{R}^2$.
A: The paper 

B.Eckmann, Räume mit Mittelbildungen, Comment.Math.Helv. 28(1954),
  329-340

contains most of the answers given so far. The results of this paper are summarized in the following very interesting note of Benno Eckmann:

B. Eckmann, Social choice and topology.

where he defines $n$-means as symmetric functions $\prod_{i=1}^nX\to X$ such that precomposing with the diagonal gives the identity. The means in this mathoverflow question are, in this new language, $2$-means. He proves:
Theorem 6: If a finite polyhedron admits $n$-means for some $n$, then it is contractible.
Theorem 7 + Theorem 4: A polyhedron $X$ admits $n$-means for all $n$ if and only if either it is contractible or it has the homotoy type of a product of rational Eilenberg Mac Lane spaces.
Theorem 2. If a space $X$ admits an n-mean for some n ≥ 2 then $\pi_1(X)$ is Abelian, multiplication by n is an automorphism of $\pi_k(X)$ for all $k$, and $\pi_k(X)$ is uniquely divisible by $n$.
