Answer
See the detailed answer below.
Work Step by Step
According to Gauss’s law,
$$\oint \vec E d \vec A=\dfrac{Q_{in}}{\epsilon_0}$$
Hence,
$$EA_{sphere}=\dfrac{Q_{in}}{\epsilon_0}$$
So the electric field is given by
$$E=\dfrac{Q_{in}}{A_{sphere}\epsilon_0}$$
$$E=\dfrac{Q_{in}}{4\pi r^2\epsilon_0}$$
where $r$ is the radius of the Gaussian sphere.
We will use this formula to find the electric field for both cases.
$$\color{blue}{\bf [a]}$$
$\bullet$ when $r\lt R$,
$$E=\dfrac{Q_{in}}{4\pi r^2\epsilon_0}$$
where $Q_{in}=+q$
$$E=\dfrac{q}{4\pi r^2\epsilon_0}$$
Hence,
$$\boxed{\vec E=\dfrac{1}{4\pi \epsilon_0}\dfrac{q}{r^2}\;\hat r}\tag{Outward}$$
$$\color{blue}{\bf [b]}$$
$\bullet$ when $r\gt R$,
$$E=\dfrac{Q_{in}}{4\pi r^2\epsilon_0}$$
where $Q_{in}=-2q+q=-q$
$$E=\dfrac{-q}{4\pi r^2\epsilon_0}$$
Hence,
$$\boxed{\vec E=\dfrac{-1}{4\pi \epsilon_0}\dfrac{q}{r^2}\;\hat r}\tag{Inward}$$