Beyond Intro R

The goal of this workshop is to build upon “introductory content” that is found in other workshops such as Data Carpentry - Data Analysis and Visualisation for Ecologists.

The workshop itself is a bit piecemeal and covers a range of topics and is mostly designed as a source of quick reference for the instructor during the session

The key themes of the workshop are to:

The main reference material is the package documentation itself

R Syntax Refresher

Maths

Mathematical operations:

  • + and - for addition and subtraction
  • *, /, and %% for multiplication, division, and remainder division
  • ^ for exponentiation
  • ( and ) for bracketing
  • Precedence of operators follows BEDMAS
1 + 6
[1] 7
5 - 3
[1] 2
2 * 9
[1] 18
8 / 4
[1] 2
9 %% 2
[1] 1
2 ^ 3
[1] 8

Assignment

a <- 7

a
[1] 7

Vectors

  • must be all of the same type
    • numeric
    • character
    • boolean
b <-c(2, 5, 6)

Indexing (starts from 1)

# 3rd item
b[3]
[1] 6
# Exclude the 2nd item
b[-2]
[1] 2 6

Subsetting with by comparison

# items in b larger than 3
b[ b > 3]
[1] 5 6
# items in b that are equal to 6
b[ b == 6]
[1] 6