September 10, 2025

Our tool

Drawing


“If you want to learn to think you need a dialogue”

Immanuel Kant, 1786

Plan for the next two hours

  • Very brief introduction to R (5-10’)
  • Very brief instructions on how to download/install R/RStudio (5’)
  • Very brief basic demonstration of how to use R (console, editor, how to save work etc.) (10’)
  • Demonstration of basic R and fundamental statistical skills (data exploration, manipulation, basic statistics, visuals) (30’)
  • Real world example (by hand) (20-30’)
  • Real world example (using Julius.ai) (20-30’)
  • If there is time: Demonstration of RMarkdown as a. ‘Reproducible reporting’ tool, but also for slides
  • Room for questions/requests

What’s R? Who wants R?

  • A free statistics package, created by Ross Ihaka (Prof. at UoA) and Robert Gentleman in the early nineties
  • Now covering everything from data processing to graphing
  • Based on a command line interface
  • R has become the data processing, analysis, plotting and programming tool in science
  • Your (future?) employer may well ask for your R skills!
  • Commercial users include Google, Pfizer, Shell, Bank of America… but also DOC, crown research institutes, councils…
  • Enormous free online resources (helplists, code)
  • Enormous AI capabilities

R-ticulate

Bit of publicity for our book…

Drawing

Is it worth learning R? Can I use Excel?

  • The short answer is: there is no way around R if you are working in the science/data space. Excel is great, but it is not a scientific tool
  • R has become the ‘lingua franca’ among scientists
  • My recommendation to use R is not commercially motivated (R is free)
  • The fact that you don’t need to buy a license has made R so successful

What can R do?

The ‘Excel mess’

The ‘art of R’ - reproducible reporting!

RStudio

The R syntax

  • …is intuitive, because your commands are interactive
[1] 5
[1] 3
Error in sqrt("Peter"): non-numeric argument to mathematical function
  • …is intuitive, because the structure remains always the same:

function(argument1 = value1, argument2 = value2, ...)

Example: the function round, the first argument are the numbers you want to round, and the second argument the decimals you would like to retain (see lab!)

[1] 4.35

If you would like to get started at home

  • Download and install R (google ‘R software’ > Download R for Windows/mac)
  • Close R
  • Download and install RStudio (google ‘Rstudio’)
  • Open RStudio
  • Go to file > new file > R Script
  • Go to file > new file > R Markdown
  • Start playing :)

The most commonly used functions

  • 80/20 Rule: 102 functions likely handle 80% of common R tasks

  • Learning Priority: Master these functions before exploring specialized packages

  • Categories Matter: Functions cluster into logical groups for systematic learning

  • Data Structure (10 functions): Foundation for all R work

  • Statistics (10 functions): Core analytical capabilities

  • Data Transformation (8 functions): Essential for data wrangling

  • Visualization (8 functions): Critical for exploratory analysis

Essential Data Structure Functions
Function Purpose
c() Combine values
data.frame() Create data frame
list() Create list
matrix() Create matrix
array() Create array
head() Show first rows
tail() Show last rows
str() Display structure
summary() Summary statistics
class() Get object class

Core Statistical and Mathematical Functions
Category Function Description
Statistics mean() Calculate mean
Statistics median() Calculate median
Statistics sd() Standard deviation
Statistics min() Find minimum
Statistics max() Find maximum
Mathematics abs() Absolute value
Mathematics sqrt() Square root
Mathematics exp() Exponential
Mathematics log() Natural logarithm
Mathematics round() Round numbers

Visualization and Statistical Modeling Functions
Category Function Usage
Base Plotting plot() Scatter plots
Base Plotting hist() Histograms
Base Plotting boxplot() Box plots
Base Plotting barplot() Bar charts
Statistical Modeling lm() Linear models
Statistical Modeling glm() Generalized linear models
Statistical Modeling t.test() T-tests