Skip to main content Skip to navigation

R Workshop

R Workshop

Welcome to the R workshop! R is a free and widely used statistical programming language. Employees of companies such as Google and Microsoft use R to process, analyse and visualise data. Work in R is supported by code written by leading academics in mathematics, statistics and many other areas. If you work in data analysis in your future career then knowing how to use R will be a very useful skill. This workshop gives you the chance to explore and learn R.

This Workshop expect no prior knowledge of programming and is split into 4 parts.

  1. Starting - installing R and RStudio, performing basic mathematical operations and the loading and saving of data.
  2. Exploring - getting help, looking at the structure of data, exploring and the basic manipulation of data.
  3. Visualising - creating basic visualisations, making your own functions and using loops.
  4. Extending - considers how we can extend the functionality of R using code other people have written called packages.

Taken together, they offer an introduction to much of the core functionality of R.

Before we start the session please download these files:

  1. Data and code files available here
  2. The current MacOS installer for R is here
  3. The current MacOS installer for RStudio is here

Instructions for install R and RStudio on Mac can be found here.

We are going to through each of the four parts together. The demonstrator will show you how to do some operations in R. You can run the code on your computer and follow through line by line. Then you have the chance to play around in R either using the code written by the experimenter and perhaps looking at the other data.

We have four data sets to play with. The demonstrator will show you some Twitter data. We have also collected YouTube comments, YouTube video information and Facebook comments. These others data files can be used to help you explore the content the demonstrator shows you in each part.

We may not complete all 4 sections. You are very welcome to work through any remaining content at your own pace and send questions to iain.emsley@warwick.ac.uk.

Part 1 - Starting


Play Point

R commands: version, c, sqrt, exp, runif, read.csv, write.csv, save.image, load.

Suggested tasks:

  • Run through each line of code in the demonstration file and try to understand what each does.
  • Ask questions! The demonstrators will be walking around offering support.
  • Explore the RStudio interface. Can you guess what each section does?
  • Try and load the other data files.
  • Look up others mathematical functions from here and use them.

Part 2 - Exploring

Play Point

R commands: ?, str, is.numeric, is.data.frame, is.factor, if, print, read.csv, load, save.image, $, [], names, sum.

Suggested tasks:

  • Work through the code yourself. Run and understand each line if you can. Feel free to ask questions.
  • Load the other data sets. Look at the structure oof the data. What is in each data set and what could you do with the data?
  • Try applying different mathematical operations such as exp to the data.
  • Check the help documentation for the R commands you have used so far. What are the different sections of the help file and how might they be useful to you?

Part 3 - Visualising

Play Point

R commands: load, plot, pie, barplot, function, class, print, for, save.image.

Suggested tasks:

  • Work through the code and understand each line. Ask if anything is unclear.
  • Plot different columns from the other data files. Did you encounter any problems? What are the best visualisations for the data and why?
  • Try and add other arguments such as 'main=' when creating a plot. If you are stuck access the help documentation or ask the demonstrator.
  • For loops and functions are hard concepts. They are best understood as saving times for the programmer and reducing errors. Loops allow easy repetition of code. Functions allow you to do the same things over and over without writing it out eachtime.
  • What are the advantages of using R compared to Excel or another program such as SPSS?

Part 4 - Extending

Play Point

R commands: load, names, c, str, RSiteSearch, install.packages, require, leaflet, addTiles, addMarkers as.data.frame, table, strsplit, paste, wordcloud, ggplot, geom_bar, geom_point, coord_flip, scale_fill_brewer.

Suggested tasks:

  • Run through the code and make sure you understand each line. If anything is unclear then please do ask.
  • Plot the other data using ggplot2 and words using wordcloud if you can. How does ggplot2 differ from the base plot functions like plot, pie and barplot?
  • Can you find packages for downloading data from social media such as Twitter , YouTube and Facebook?
  • Explore the available packages on CRAN. Many popular packages are organised into view here.