First, remove the installed version of R using:
sudo apt purge r-base
You should also uninstall any other R packages that you may have installed.
As stated in the R installation guide, for 16.04 you need to add the repository deb https://cloud.r-project.org/bin/linux/ubuntu xenial-cran35/
to /etc/apt/sources.list
. There is a longer and a shorter way to do this.
Longer way:
To add the repository open a terminal and run:
sudo nano /etc/apt/sources.list
Copy and paste deb https://cloud.r-project.org/bin/linux/ubuntu xenial-cran35/
at the end of the file (paste is Ctrl+Shift+V for nano
).
Then add the public key for the repository running the following command:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
Finally, update your system to enable the repository:
sudo apt update
Shorter way:
You can add the repository, key and update as a one-line terminal command:
sudo bash -c 'echo "deb https://cloud.r-project.org/bin/linux/ubuntu xenial-cran35/" >> /etc/apt/sources.list' && sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9 && sudo apt update
Whichever way you selected, you should be able to install R 3.6 by running:
sudo apt install r-base