  A set $R\subset \mathbb{N}$ is called rational if it is well-approximable by
finite unions of arithmetic progressions. Examples of rational sets include
many classical sets of number-theoretical origin such as the set of squarefree
numbers, the set of abundant numbers, or sets of the form
$\Phi_x:=\{n\in\mathbb{N}: \frac{\boldsymbol{\varphi}(n)}{n}<x\}$, where
$x\in[0,1]$ and $\boldsymbol{\varphi}$ is Euler's totient function. We
investigate the combinatorial and dynamical properties of rational sets and
obtain new results in ergodic Ramsey theory. We show that if $R$ is a rational
set with $\overline{d}(R)>0$, then the following are equivalent:
  (a) $R$ is divisible, i.e. $\overline{d}(R\cap u \mathbb{N})>0$ for all
$u\in\mathbb{N}$.
  (b) $R$ is an averaging set of polynomial single recurrence.
  (c) $R$ is an averaging set of polynomial multiple recurrence.
  As an application, we show that if $R$ is rational and divisible, then for
any set $E\subset\mathbb{N}$ with $\overline{d}(E)>0$ and any polynomials
$p_i\in\mathbb{Q}[t]$,$i=1,\ldots,\ell$, which satisfy
$p_i(\mathbb{Z})\subset\mathbb{Z}$ and $p_i(0)=0$ for all
$i\in\{1,\ldots,\ell\}$, there exists $\beta>0$ such that the set $$\{n\in
R:\overline{d}( E\cap (E-p_1(n))\cap\ldots\cap(E-p_\ell(n)))>\beta\}$$ has
positive lower density.
  Ramsey-theoretical applications naturally lead to problems in symbolic
dynamics, which involve rationally almost periodic sequences. We prove that if
$\mathcal{A}$ is a finite alphabet, $\eta\in\mathcal{A}^\mathbb{N}$ is
rationally almost periodic, $S$ denotes the left-shift on
$\mathcal{A}^\mathbb{Z}$ and $$X:=\{y\in \mathcal{A}^\mathbb{Z} : \text{each
finite word appearing in $y$ appears in }\eta\},$$ then $\eta$ is a generic
point for an $S$-invariant probability measure $\nu$ on $X$ such that
$(X,\nu,S)$ is ergodic and has rational discrete spectrum.
