2. Essentials of the R Language

  1. Michael J. Crawley

Published Online: 6 NOV 2012

DOI: 10.1002/9781118448908.ch2

The R Book, Second Edition

The R Book, Second Edition

How to Cite

Crawley, M. J. (2012) Essentials of the R Language, in The R Book, Second Edition, John Wiley & Sons, Ltd, Chichester, UK. doi: 10.1002/9781118448908.ch2

Author Information

  1. Imperial College London at Silwood Park, UK

Publication History

  1. Published Online: 6 NOV 2012
  2. Published Print: 7 DEC 2012

ISBN Information

Print ISBN: 9780470973929

Online ISBN: 9781118448908



  • essentials of the R language;
  • calculations, complex numbers in R;
  • logical operations, TRUE and T with FALSE and F;
  • testing for equality with real numbers;
  • vector functions, tables of means using tapply;
  • matrices and arrays, sweep, apply/sapply/lapply;
  • random numbers, sampling and shuffling;
  • loops and repeats, for time series;
  • writing R functions, returning values from a function;
  • writing from R to file, Excel readable file from R


This chapter contains sections titled:

  • Calculations

  • Logical operations

  • Generating sequences

  • Membership: Testing and coercing in R

  • Missing values, infinity and things that are not numbers

  • Vectors and subscripts

  • Vector functions

  • Matrices and arrays

  • Random numbers, sampling and shuffling

  • Loops and repeats

  • Lists

  • Text, character strings and pattern matching

  • Dates and times in R

  • Environments

  • Writing R functions

  • Writing from R to file

  • Programming tips