4. Dataframes

  1. Michael J. Crawley

Published Online: 6 NOV 2012

DOI: 10.1002/9781118448908.ch4

The R Book, Second Edition

The R Book, Second Edition

How to Cite

Crawley, M. J. (2012) Dataframes, in The R Book, Second Edition, John Wiley & Sons, Ltd, Chichester, UK. doi: 10.1002/9781118448908.ch4

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



  • dataframes, subscripts and indices;
  • selecting rows from the dataframe at random;
  • using order and !duplicated, eliminating pseudoreplication;
  • complex ordering with mixed directions;
  • dataframe creation from another kind of object;
  • dataframe, and duplicate row elimination;
  • dataframes and dates;
  • the match function in dataframes;
  • the two dataframe merge;
  • dataframe, and adding margins


This chapter contains sections titled:

  • Subscripts and indices

  • Selecting rows from the dataframe at random

  • Sorting dataframes

  • Using logical conditions to select rows from the dataframe

  • Omitting rows containing missing values, NA

  • Using order and !duplicated to eliminate pseudoreplication

  • Complex ordering with mixed directions

  • A dataframe with row names instead of row numbers

  • Creating a dataframe from another kind of object

  • Eliminating duplicate rows from a dataframe

  • Dates in dataframes

  • Using the match function in dataframes

  • Merging two dataframes

  • Adding margins to a dataframe

  • Summarizing the contents of dataframes