Cover image for R Cookbook

Book description

Perform data analysis with R quickly and efficiently using the task-oriented recipes in this cookbook. The R language and environment include everything necessary to perform statistical work right out of the box, but its structure can often be difficult for beginners and experienced computer geeks alike. R Cookbook offers a collection of concise recipes that will help you be productive with R immediately.

Table of Contents

  1. R Cookbook
  2. Preface
    1. The Recipes
    2. A Note on Terminology
    3. Software and Platform Notes
    4. Other Resources
    5. Conventions Used in This Book
    6. Using Code Examples
    7. Safari® Books Online
    8. How to Contact Us
    9. Acknowledgments
  3. 1. Getting Started and Getting Help
    1. Introduction
    2. 1.1. Downloading and Installing R
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. 1.2. Starting R
      1. Problem
      2. Solution
      3. Discussion
      4. Starting on Windows
      5. Starting on OS X
      6. Starting on Linux and Unix
      7. See Also
    4. 1.3. Entering Commands
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. 1.4. Exiting from R
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. 1.5. Interrupting R
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. 1.6. Viewing the Supplied Documentation
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. 1.7. Getting Help on a Function
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    9. 1.8. Searching the Supplied Documentation
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. 1.9. Getting Help on a Package
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    11. 1.10. Searching the Web for Help
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    12. 1.11. Finding Relevant Functions and Packages
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    13. 1.12. Searching the Mailing Lists
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    14. 1.13. Submitting Questions to the Mailing Lists
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  4. 2. Some Basics
    1. Introduction
    2. 2.1. Printing Something
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. 2.2. Setting Variables
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. 2.3. Listing Variables
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. 2.4. Deleting Variables
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. 2.5. Creating a Vector
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. 2.6. Computing Basic Statistics
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. 2.7. Creating Sequences
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    9. 2.8. Comparing Vectors
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. 2.9. Selecting Vector Elements
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    11. 2.10. Performing Vector Arithmetic
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    12. 2.11. Getting Operator Precedence Right
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    13. 2.12. Defining a Function
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    14. 2.13. Typing Less and Accomplishing More
      1. Problem
      2. Solution
      3. Discussion
    15. 2.14. Avoiding Some Common Mistakes
      1. Problem
      2. Discussion
      3. See Also
  5. 3. Navigating the Software
    1. Introduction
    2. 3.1. Getting and Setting the Working Directory
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. 3.2. Saving Your Workspace
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. 3.3. Viewing Your Command History
      1. Problem
      2. Solution
      3. Discussion
    5. 3.4. Saving the Result of the Previous Command
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. 3.5. Displaying the Search Path
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. 3.6. Accessing the Functions in a Package
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. 3.7. Accessing Built-in Datasets
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    9. 3.8. Viewing the List of Installed Packages
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. 3.9. Installing Packages from CRAN
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    11. 3.10. Setting a Default CRAN Mirror
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    12. 3.11. Suppressing the Startup Message
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    13. 3.12. Running a Script
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    14. 3.13. Running a Batch Script
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    15. 3.14. Getting and Setting Environment Variables
      1. Problem
      2. Solution
      3. Discussion
    16. 3.15. Locating the R Home Directory
      1. Problem
      2. Solution
      3. Discussion
    17. 3.16. Customizing R
      1. Problem
      2. Solution
      3. Discussion
      4. Setting Options
      5. Loading Packages
      6. Startup Sequence
      7. See Also
  6. 4. Input and Output
    1. Introduction
      1. A Philosophical Note
    2. 4.1. Entering Data from the Keyboard
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. 4.2. Printing Fewer Digits (or More Digits)
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. 4.3. Redirecting Output to a File
      1. Problem
      2. Solution
      3. Discussion
    5. 4.4. Listing Files
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. 4.5. Dealing with “Cannot Open File” in Windows
      1. Problem
      2. Solution
      3. Discussion
    7. 4.6. Reading Fixed-Width Records
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. 4.7. Reading Tabular Data Files
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    9. 4.8. Reading from CSV Files
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. 4.9. Writing to CSV Files
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    11. 4.10. Reading Tabular or CSV Data from the Web
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    12. 4.11. Reading Data from HTML Tables
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    13. 4.12. Reading Files with a Complex Structure
      1. Problem
      2. Solution
      3. Discussion
      4. An Example
    14. 4.13. Reading from MySQL Databases
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    15. 4.14. Saving and Transporting Objects
      1. Problem
      2. Solution
      3. Discussion
  7. 5. Data Structures
    1. Introduction
      1. Vectors
      2. Lists
      3. Mode: Physical Type
      4. Class: Abstract Type
      5. Scalars
      6. Matrices
      7. Arrays
      8. Factors
      9. Data Frames
    2. 5.1. Appending Data to a Vector
      1. Problem
      2. Solution
      3. Discussion
    3. 5.2. Inserting Data into a Vector
      1. Problem
      2. Solution
      3. Discussion
    4. 5.3. Understanding the Recycling Rule
      1. Problem
      2. Discussion
    5. 5.4. Creating a Factor (Categorical Variable)
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. 5.5. Combining Multiple Vectors into One Vector and a Factor
      1. Problem
      2. Solution
      3. Discussion
    7. 5.6. Creating a List
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. 5.7. Selecting List Elements by Position
      1. Problem
      2. Solution
      3. Discussion
    9. 5.8. Selecting List Elements by Name
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. 5.9. Building a Name/Value Association List
      1. Problem
      2. Solution
      3. Discussion
    11. 5.10. Removing an Element from a List
      1. Problem
      2. Solution
      3. Discussion
    12. 5.11. Flatten a List into a Vector
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    13. 5.12. Removing NULL Elements from a List
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    14. 5.13. Removing List Elements Using a Condition
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    15. 5.14. Initializing a Matrix
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    16. 5.15. Performing Matrix Operations
      1. Problem
      2. Solution
      3. Discussion
    17. 5.16. Giving Descriptive Names to the Rows and Columns of a Matrix
      1. Problem
      2. Solution
      3. Discussion
    18. 5.17. Selecting One Row or Column from a Matrix
      1. Problem
      2. Solution
      3. Discussion
    19. 5.18. Initializing a Data Frame from Column Data
      1. Problem
      2. Solution
      3. Discussion
    20. 5.19. Initializing a Data Frame from Row Data
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    21. 5.20. Appending Rows to a Data Frame
      1. Problem
      2. Solution
      3. Discussion
    22. 5.21. Preallocating a Data Frame
      1. Problem
      2. Solution
      3. Discussion
    23. 5.22. Selecting Data Frame Columns by Position
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    24. 5.23. Selecting Data Frame Columns by Name
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    25. 5.24. Selecting Rows and Columns More Easily
      1. Problem
      2. Solution
      3. Discussion
    26. 5.25. Changing the Names of Data Frame Columns
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    27. 5.26. Editing a Data Frame
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    28. 5.27. Removing NAs from a Data Frame
      1. Problem
      2. Solution
      3. Discussion
    29. 5.28. Excluding Columns by Name
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    30. 5.29. Combining Two Data Frames
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    31. 5.30. Merging Data Frames by Common Column
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    32. 5.31. Accessing Data Frame Contents More Easily
      1. Problem
      2. Solution
      3. Discussion
    33. 5.32. Converting One Atomic Value into Another
      1. Problem
      2. Solution
      3. Discussion
    34. 5.33. Converting One Structured Data Type into Another
      1. Problem
      2. Solution
      3. Discussion
        1. Problems with matrices
      4. See Also
  8. 6. Data Transformations
    1. Introduction
      1. Defining Groups Via a Factor
    2. 6.1. Splitting a Vector into Groups
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. 6.2. Applying a Function to Each List Element
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. 6.3. Applying a Function to Every Row
      1. Problem
      2. Solution
      3. Discussion
    5. 6.4. Applying a Function to Every Column
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. 6.5. Applying a Function to Groups of Data
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. 6.6. Applying a Function to Groups of Rows
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. 6.7. Applying a Function to Parallel Vectors or Lists
      1. Problem
      2. Solution
      3. Discussion
  9. 7. Strings and Dates
    1. Introduction
      1. Classes for Dates and Times
      2. See Also
    2. 7.1. Getting the Length of a String
      1. Problem
      2. Solution
      3. Discussion
    3. 7.2. Concatenating Strings
      1. Problem
      2. Solution
      3. Discussion
    4. 7.3. Extracting Substrings
      1. Problem
      2. Solution
      3. Discussion
    5. 7.4. Splitting a String According to a Delimiter
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. 7.5. Replacing Substrings
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. 7.6. Seeing the Special Characters in a String
      1. Problem
      2. Solution
      3. Discussion
    8. 7.7. Generating All Pairwise Combinations of Strings
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    9. 7.8. Getting the Current Date
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. 7.9. Converting a String into a Date
      1. Problem
      2. Solution
      3. Discussion
    11. 7.10. Converting a Date into a String
      1. Problem
      2. Solution
      3. Discussion
    12. 7.11. Converting Year, Month, and Day into a Date
      1. Problem
      2. Solution
      3. Discussion
    13. 7.12. Getting the Julian Date
      1. Problem
      2. Solution
      3. Discussion
    14. 7.13. Extracting the Parts of a Date
      1. Problem
      2. Solution
      3. Discussion
    15. 7.14. Creating a Sequence of Dates
      1. Problem
      2. Solution
      3. Discussion
  10. 8. Probability
    1. Introduction
      1. Names of Distributions
      2. Getting Help on Probability Distributions
      3. See Also
    2. 8.1. Counting the Number of Combinations
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. 8.2. Generating Combinations
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. 8.3. Generating Random Numbers
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. 8.4. Generating Reproducible Random Numbers
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. 8.5. Generating a Random Sample
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. 8.6. Generating Random Sequences
      1. Problem
      2. Solution
      3. Discussion
    8. 8.7. Randomly Permuting a Vector
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    9. 8.8. Calculating Probabilities for Discrete Distributions
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. 8.9. Calculating Probabilities for Continuous Distributions
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    11. 8.10. Converting Probabilities to Quantiles
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    12. 8.11. Plotting a Density Function
      1. Problem
      2. Solution
      3. Discussion
  11. 9. General Statistics
    1. Introduction
      1. Null Hypotheses, Alternative Hypotheses, and p-Values
      2. Confidence Intervals
      3. See Also
    2. 9.1. Summarizing Your Data
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. 9.2. Calculating Relative Frequencies
      1. Problem
      2. Solution
      3. Discussion
    4. 9.3. Tabulating Factors and Creating Contingency Tables
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. 9.4. Testing Categorical Variables for Independence
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. 9.5. Calculating Quantiles (and Quartiles) of a Dataset
      1. Problem
      2. Solution
      3. Discussion
    7. 9.6. Inverting a Quantile
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. 9.7. Converting Data to Z-Scores
      1. Problem
      2. Solution
      3. Discussion
    9. 9.8. Testing the Mean of a Sample (t Test)
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. 9.9. Forming a Confidence Interval for a Mean
      1. Problem
      2. Solution
      3. Discussion
    11. 9.10. Forming a Confidence Interval for a Median
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    12. 9.11. Testing a Sample Proportion
      1. Problem
      2. Solution
      3. Discussion
    13. 9.12. Forming a Confidence Interval for a Proportion
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    14. 9.13. Testing for Normality
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    15. 9.14. Testing for Runs
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    16. 9.15. Comparing the Means of Two Samples
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    17. 9.16. Comparing the Locations of Two Samples Nonparametrically
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    18. 9.17. Testing a Correlation for Significance
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    19. 9.18. Testing Groups for Equal Proportions
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    20. 9.19. Performing Pairwise Comparisons Between Group Means
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    21. 9.20. Testing Two Samples for the Same Distribution
      1. Problem
      2. Solution
      3. Discussion
  12. 10. Graphics
    1. Introduction
      1. The Illustrations
      2. Notes on Graphics Functions
      3. The Generic plot Function
      4. Graphics in Other Packages
    2. 10.1. Creating a Scatter Plot
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. 10.2. Adding a Title and Labels
      1. Problem
      2. Solution
      3. Discussion
    4. 10.3. Adding a Grid
      1. Problem
      2. Solution
      3. Discussion
    5. 10.4. Creating a Scatter Plot of Multiple Groups
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. 10.5. Adding a Legend
      1. Problem
      2. Solution
      3. Discussion
    7. 10.6. Plotting the Regression Line of a Scatter Plot
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. 10.7. Plotting All Variables Against All Other Variables
      1. Problem
      2. Solution
      3. Discussion
    9. 10.8. Creating One Scatter Plot for Each Factor Level
      1. Problem
      2. Solution
      3. Discussion
    10. 10.9. Creating a Bar Chart
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    11. 10.10. Adding Confidence Intervals to a Bar Chart
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    12. 10.11. Coloring a Bar Chart
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    13. 10.12. Plotting a Line from x and y Points
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    14. 10.13. Changing the Type, Width, or Color of a Line
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    15. 10.14. Plotting Multiple Datasets
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    16. 10.15. Adding Vertical or Horizontal Lines
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    17. 10.16. Creating a Box Plot
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    18. 10.17. Creating One Box Plot for Each Factor Level
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    19. 10.18. Creating a Histogram
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    20. 10.19. Adding a Density Estimate to a Histogram
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    21. 10.20. Creating a Discrete Histogram
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    22. 10.21. Creating a Normal Quantile-Quantile (Q-Q) Plot
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    23. 10.22. Creating Other Quantile-Quantile Plots
      1. Problem
      2. Solution
      3. Discussion
    24. 10.23. Plotting a Variable in Multiple Colors
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    25. 10.24. Graphing a Function
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    26. 10.25. Pausing Between Plots
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    27. 10.26. Displaying Several Figures on One Page
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    28. 10.27. Opening Additional Graphics Windows
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    29. 10.28. Writing Your Plot to a File
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    30. 10.29. Changing Graphical Parameters
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  13. 11. Linear Regression and ANOVA
    1. Introduction
      1. ANOVA
      2. See Also
    2. 11.1. Performing Simple Linear Regression
      1. Problem
      2. Solution
      3. Discussion
    3. 11.2. Performing Multiple Linear Regression
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. 11.3. Getting Regression Statistics
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. 11.4. Understanding the Regression Summary
      1. Problem
      2. Discussion
      3. See Also
    6. 11.5. Performing Linear Regression Without an Intercept
      1. Problem
      2. Solution
      3. Discussion
    7. 11.6. Performing Linear Regression with Interaction Terms
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. 11.7. Selecting the Best Regression Variables
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    9. 11.8. Regressing on a Subset of Your Data
      1. Problem
      2. Solution
      3. Discussion
    10. 11.9. Using an Expression Inside a Regression Formula
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    11. 11.10. Regressing on a Polynomial
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    12. 11.11. Regressing on Transformed Data
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    13. 11.12. Finding the Best Power Transformation (Box–Cox Procedure)
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    14. 11.13. Forming Confidence Intervals for Regression Coefficients
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    15. 11.14. Plotting Regression Residuals
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    16. 11.15. Diagnosing a Linear Regression
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    17. 11.16. Identifying Influential Observations
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    18. 11.17. Testing Residuals for Autocorrelation (Durbin–Watson Test)
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    19. 11.18. Predicting New Values
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    20. 11.19. Forming Prediction Intervals
      1. Problem
      2. Solution
      3. Discussion
    21. 11.20. Performing One-Way ANOVA
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    22. 11.21. Creating an Interaction Plot
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    23. 11.22. Finding Differences Between Means of Groups
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    24. 11.23. Performing Robust ANOVA (Kruskal–Wallis Test)
      1. Problem
      2. Solution
      3. Discussion
    25. 11.24. Comparing Models by Using ANOVA
      1. Problem
      2. Solution
      3. Discussion
  14. 12. Useful Tricks
    1. Introduction
    2. 12.1. Peeking at Your Data
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. 12.2. Widen Your Output
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. 12.3. Printing the Result of an Assignment
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. 12.4. Summing Rows and Columns
      1. Problem
      2. Solution
      3. Discussion
    6. 12.5. Printing Data in Columns
      1. Problem
      2. Solution
      3. Discussion
    7. 12.6. Binning Your Data
      1. Problem
      2. Solution
      3. Discussion
    8. 12.7. Finding the Position of a Particular Value
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    9. 12.8. Selecting Every nth Element of a Vector
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. 12.9. Finding Pairwise Minimums or Maximums
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    11. 12.10. Generating All Combinations of Several Factors
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    12. 12.11. Flatten a Data Frame
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    13. 12.12. Sorting a Data Frame
      1. Problem
      2. Solution
      3. Discussion
    14. 12.13. Sorting by Two Columns
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    15. 12.14. Stripping Attributes from a Variable
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    16. 12.15. Revealing the Structure of an Object
      1. Problem
      2. Solution
      3. Discussion
    17. 12.16. Timing Your Code
      1. Problem
      2. Solution
      3. Discussion
    18. 12.17. Suppressing Warnings and Error Messages
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    19. 12.18. Taking Function Arguments from a List
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    20. 12.19. Defining Your Own Binary Operators
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  15. 13. Beyond Basic Numerics and Statistics
    1. Introduction
    2. 13.1. Minimizing or Maximizing a Single-Parameter Function
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. 13.2. Minimizing or Maximizing a Multiparameter Function
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. 13.3. Calculating Eigenvalues and Eigenvectors
      1. Problem
      2. Solution
      3. Discussion
    5. 13.4. Performing Principal Component Analysis
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. 13.5. Performing Simple Orthogonal Regression
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. 13.6. Finding Clusters in Your Data
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. 13.7. Predicting a Binary-Valued Variable (Logistic Regression)
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    9. 13.8. Bootstrapping a Statistic
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. 13.9. Factor Analysis
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  16. 14. Time Series Analysis
    1. Introduction
      1. Date Versus Datetime
      2. See Also
    2. 14.1. Representing Time Series Data
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. 14.2. Plotting Time Series Data
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. 14.3. Extracting the Oldest or Newest Observations
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. 14.4. Subsetting a Time Series
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. 14.5. Merging Several Time Series
      1. Problem
      2. Solution
      3. Discussion
    7. 14.6. Filling or Padding a Time Series
      1. Problem
      2. Solution
      3. Discussion
    8. 14.7. Lagging a Time Series
      1. Problem
      2. Solution
      3. Discussion
    9. 14.8. Computing Successive Differences
      1. Problem
      2. Solution
      3. Discussion
    10. 14.9. Performing Calculations on Time Series
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    11. 14.10. Computing a Moving Average
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    12. 14.11. Applying a Function by Calendar Period
      1. Problem
      2. Solution
      3. Discussion
    13. 14.12. Applying a Rolling Function
      1. Problem
      2. Solution
      3. Discussion
    14. 14.13. Plotting the Autocorrelation Function
      1. Problem
      2. Solution
      3. Discussion
    15. 14.14. Testing a Time Series for Autocorrelation
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    16. 14.15. Plotting the Partial Autocorrelation Function
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    17. 14.16. Finding Lagged Correlations Between Two Time Series
      1. Problem
      2. Solution
      3. Discussion
    18. 14.17. Detrending a Time Series
      1. Problem
      2. Solution
      3. Discussion
    19. 14.18. Fitting an ARIMA Model
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    20. 14.19. Removing Insignificant ARIMA Coefficients
      1. Problem
      2. Solution
      3. Discussion
    21. 14.20. Running Diagnostics on an ARIMA Model
      1. Problem
      2. Solution
      3. Discussion
    22. 14.21. Making Forecasts from an ARIMA Model
      1. Problem
      2. Solution
      3. Discussion
    23. 14.22. Testing for Mean Reversion
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    24. 14.23. Smoothing a Time Series
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  17. Index
  18. About the Author
  19. Colophon
  20. Copyright