I'm trying to understand the following.
Let's consider $G \le S_n$. We define a $G$-invariant function as $f : \mathbb{R}^n \rightarrow \mathbb{R}$ such that
$$f(g\cdot x) =f(x) \, \, \forall x \in \mathbb{R}^n \, , \forall g \in G.$$
The action of the group on $x \in \mathbb{R}^n$ is defined as follows:
$$g \cdot x := (x_{g^{-1}(1)}, \dots , x_{g^{-1}(n)}).$$
The $G$-invariant polynomials are all polynomials that are also $G$-invariant functions and we denote them as $\mathbb{R}[x_1, \dots ,x_n]^G$.
What I want to prove is that given $p \in \mathbb{R}[x_1, \dots, x_n]$ a polynomial that is not necessarily $G$-invariant, then
$$q(x) = \frac{1}{|G|}\sum_{g \in G}p(g \cdot x)$$
is $G$-invariant.
This is a standard "averaging" argument. Given $h \in G$, you want to show that $q(h.x) = q(x)$. You have
$$q(h.x) = \frac{1}{|G|} \sum\limits_{g \in G} p(gh.x)).$$
This is just adding all the terms $p(gh.x)$, as $g$ runs through all the distinct elements of $G$. But since multiplication by $h$ permutes the elements of $G$, this is the same as just adding all the terms $p(g.x)$, as $g$ runs through the distinct elements of $G$.
This argument shows up a lot in representation theory, for example if you have a representation $\pi$ of a compact topological group $G$ on Hilbert space $V$ with inner product $\langle -,- \rangle$, you can always replace the inner product with an equivalent inner product which is $G$-invariant by defining
$$\langle v, w \rangle_1 = \frac{1}{\operatorname{volume}(G)}\int\limits_G \langle \pi(g)v, \pi(g)w \rangle \space dg.$$