Chapter 23 Introduction to R

23.1 What are R, RStudio and R Markdown?

R is a free and widely used statistical language/package. There is a huge range of statistical commands in R, from basic summary statistics to cutting edge research applications. It is also a programming environment, so you can soon build up your own routines.

RStudio is a free graphical user interface that makes using R more user-friendly. Almost all practical statistical analysis is carried out on a computer, and so becoming familiar with computer packages and languages is an essential task for any user of statistics.

To help you create beautiful output (HTML pages with mathematics included) we shall use a package called knitr which is embedded within some more general R Markdown packages, it turns your comments and code into a pretty HTML file. For each Unit I will give you an “R Markdown” file in RStudio (it ends in .Rmd) and then you can use knitr in RStudio to create the HTML. Note that you will need to edit the R Markdown file to answer the questions it contains.

23.2 Starting RStudio on the UoN Network

First of all log into the computer system. You can then start RStudio by going to the start menu and selecting

Start \(\rightarrow\) UoN Applications \(\rightarrow\) (UoN) RStudio (x.x.x)

where (x.x.x) is the latest version of RStudio available.

R is a command line based language, so you will need to type in the commands with any options and arguments. When RStudio starts a console window is opened. It is here that you type in the commands.

23.3 Downloading R and RStudio

It is recommended that you download RStudio onto your own computer to have R available when both working online and offline.

To run RStudio on your own computer then you first need to download R from CRAN (Comprehensive R Archive Network):
Download R
and then you can download RStudio from
Download R Studio

Note that both R and RStudio are free.

You can also find additional documentation on R, including introductory material, at the CRAN site.

23.4 Getting started in R

Once you have either accessed R through the UoN Network or downloaded and opened RStudio, watch the following Video: Introduction to R which gives an introduction to R and the basics of RStudio. It might be helpful, if possible, to simultaneously have RStudio open and watch the video so that you can get a feel for using RStudio.

Video R1: Introduction to R