Introduction to R: Reference

Key Points

Installing R and getting started
  • R installation is easy

  • Library installation is simple (if library is in CRAN)

  • There are multiple ways of assigning data to a variable

How data are stored
  • Factors may seem confusing at first, but will prove to be useful

  • The matrix is just a special array

  • Lists are useful for collecting objects of various length

  • Data frames are sort of like lists, but all components have the same length

Math with scalars and matrices
  • Most math is what you’d expect it to be, except matrix multiplication

  • The diag() function is multipurpose (Extract or replace the diagonal of a matrix, or construct a diagonal matrix)

Loops
  • Avoid building a vector/matrix in a loop using concatenation

  • Looping is faster now than it used to be, but avoiding loops is typically a good idea

Decision making
  • ifelse() is a great shortcut if you have a simple statement

Writing functions
  • Be careful with global variables. Make sure all variables referenced in your function are either fed in or created within the function

Plotting
Reading in data
  • fread is much faster and (typically) requires less work. You may benefit from some of the functionalities in the data.table library that should be faster than data.frame manipulations

Extra bits we probably won't have time to cover
  • fread is much faster and (typically) requires less work. You may benefit from some of the functionalities in the data.table library that should be faster than data.frame manipulations

FIXME: more reference material.