R Course Materials

An Introductory Course on the R Language and Environment for Statistical Computing.

R is a programming language and software environment for conducting statistical analyses which includes very powerful and flexible graphical capabilities.

R is available for free download here for Windows, MacOS, and Linux (R is free ‘as in free speech and free beer’).

I recommend interacting with R through an Integrated Development Environment (IDE) like RStudio which will help you write code more easily by auto-completing pairs of brackets and colour coding different elements of syntax among other things.  The Documentation section of the RStudio website is an excellent place to start if you want to learn to use RStudio – the basics however are very easy and I have covered them below.

I’ve written this course as a sequence of heavily annotated code files which you can open and execute either directly through the basic script editor provided with R or through the more elaborate RStudio.

Each code file comprises a short tutorial to be completed within R so what you need to do to start one of them is:

1) Download the code file by clicking one of the links below (this will take you to a GoogleDrive page where you need to click ‘Download’ – apologies WordPress does not host .R files)

2) Open RStudio

3) Within RStudio click on the ‘File’ menu then click ‘Open’ and navigate to where you saved the code file on your computer.

If you downloaded Code File 1 the file will be called ‘BRAG_Intro_to_R.R’ (the .R extension tells programs that the file is an R script i.e. a file of R code).

4) You will then see 4 panes in the RStudio window.

The Top Left pane is my code file and underneath it is the R console.
The code file contains R code which you execute by putting the cursor at the line you want R to execute then clicking ‘Run’.
The command then gets sent to R, R executes the command and prints the command and its results in the console window.

I have put instructions and explanations as comments alongside the code that comprises the exercises within the code files with the aim of making the tutorials as self contained as possible.

However, if you get stuck feel free to leave a comment below.

Course Materials:

Introductory Slides focusing the question: Why R?

Code File 1: Introduction to R

Excel File (.xls) containing data for one of the exercises in Code File 1

Code File 2: Introduction to producing 2D graphics with the R package ‘ggplot2’

Code File 3: Introduction to producing 3D graphics with the R package ‘rgl’

 

 

 

 

 

 

 

 

 

Code File 4: Introduction to Programming in R

– Ben R. Fitzpatrick, June 2012

2 thoughts on “R Course Materials

Leave a comment