Data frames and matrices

Writing Efficient R Code

Colin Gillespie

Jumping Rivers & Newcastle University

The data frame

  • Key data structure in R
    • Copied in other languages
      • Python: pandas data frame
      • If you can't beat them, join them!
Writing Efficient R Code

Data frames

  • Tabular structure: rows and colums
    • read.csv()and friends returns a data frame
      • Columns
    • Data must be the same type
      • Rows
    • Different type
Storage

Selection

Writing Efficient R Code

Matrices

  • It's a rectangular data structure
    • You can perform usual subsetting and extracting operations
    • BUT - every element must be the same data type
Storage

Selection

Writing Efficient R Code

R club

The third rule of R club: Use a matrix whenever appropriate.

Writing Efficient R Code

Let's practice!

Writing Efficient R Code

Preparing Video For Download...