You are here

R and MATLAB

David E. Hiebeler
Publisher: 
Chapman & Hall/CRC
Publication Date: 
2015
Number of Pages: 
211
Format: 
Hardcover
Series: 
The R Series
Price: 
69.95
ISBN: 
9781466568389
Category: 
Monograph
[Reviewed by
Jason M. Graham
, on
12/11/2015
]

R is an increasingly popular computing environment widely used for statistics and data analysis, while MATLAB is a well-established environment for scientific computing and producing graphics. Both R and MATLAB are extremely powerful and useful tools for computing and visualization in scientific research and teaching. In addition, they are also both a great deal of fun to use for programming and problem solving. There seems to be a cultural divide, however, between the users of R and the users of MATLAB. Many mathematicians and computational scientists are well versed in MATLAB but make less use of R. On the other hand, statisticians, data analysts and biologists are often fluent in R but rarely use MATLAB. This is no problem, except when researchers from the two different cultures want to collaborate. This observation largely explains the impetus for the book reviewed here.

David E. Hiebeler’s R and MATLAB can be thought of as a dictionary for translating between R and MATLAB. In fact, much of the text is organized in the following manner: it is shown how a common task in R is carried out followed by the commands to do the same thing in MATLAB, or vice-versa. But there is more to the book than simply a guide for translating from one computing environment to the other. The author also provides many useful suggestions for effective use of both R and MATLAB. Furthermore, in many places, the author explains what each environment is actually doing when a command or routine is called. This is useful because it can serve as an indicator as to whether R or MATLAB is the more appropriate choice for a given computing task.

While this book may not be the best to use as a sole source for learning MATLAB or R, it is certainly a highly valuable resource for anyone currently using or intending to use either. I envision that the best use of the book is as a guide to learning R for someone who is already familiar with MATLAB. The author himself states in the preface that he has used MATLAB for many years and more recently picked up R as a new language. I personally welcome the existence of this book and am very grateful to the author for putting in the work to write it. R and MATLAB is well-written and should be accessible to students and researchers alike.

It should be noted that David E. Hiebeler also maintains a MATLAB/R Reference available on his website.


Jason M. Graham is an assistant professor in the department of mathematics at the University of Scranton, Scranton, Pennsylvania. His current professional interests are in teaching applied mathematics and mathematical biology, and collaborating with biologists specializing in the collective behavior of groups of organisms.

Installing and Running R and MATLAB
Obtaining and installing
Commands for getting help
Demos
Quitting
Additional resources

 

Getting Started: Variables and Basic Computations
Variable names
Assignment statements
Basic computations
Formatting of output
Other computations
Complex numbers
Strange variable names in R
Data types

 

Matrices and Vectors
Overview
Creating vectors
Working with vectors
Creating matrices
Working with matrices
Reshaping matrices, and higher-dimensional arrays
Sparse matrices
Names with vectors and matrices/arrays
Miscellaneous

 

Matrix/Vector Calculations and Functions
Applying a function to rows or columns of a matrix
Applying a function to all elements of a matrix
Linear algebra calculations with vectors and matrices
Statistical calculations
Vectorized logical tests
Other calculations

 

Lists and Cell Arrays
Creating lists and cell arrays
Using lists and cell arrays
Applying functions to all elements of lists and cell arrays
Converting other data types to lists and cell arrays
Converting lists and cell arrays to other data types

 

Flow Control
Conditional ("if") statements
"If/else" statements
"for" loops
"while" loops
Breaking out of loops
"switch" statements
"ifelse" statements in R

 

Running Code from Files: Scripts
Current working directory
The MATLAB search path
Executing code from a file
Creating a new script document in the editor
Comments in script files
Executing code from the editor window
Summary of differences

 

Writing Your Own Functions
R
MATLAB
Summary of main differences

 

Probability and Random Numbers
Basic random values, permutations, and samples
Random number seed
Random variates from probability distributions
PDFs, CDFs, and inverse CDFs

 

Graphics
Creating, selecting, and closing figure windows
Basic 2-D scatterplots
Adding additional plots to a figure
Axis ranges
Logarithmic axis scales
Background grid
Plotting multiple data sets simultaneously
Axis labels and figure titles
Adding text to figures
Greek letters and mathematical symbols
Arrows
Figure legends
Size and font adjustments
Two y axes
Plotting functions
Image plots and contours
Colormaps
3-D plotting
Multiple subplots in one figure
Saving figures
Other types of plots
Final notes about graphics

 

Numerical Computing
Root-finding
Univariate optimization
Multivariate optimization
Numerical integration
Curve fitting
Differential equations

 

File Input and Output
Opening files
Reading a table of numbers
Reading numeric data with a different comment character
Reading numbers from a file where different lines have varying numbers of values
Reading numbers and strings
Reading the raw character data in, a line at a time
Writing a table of numbers
Writing a set of strings
Saving and loading variables in binary format
Images
URLs
Excel files

 

Miscellaneous
Working with variables
Character strings
Reading user input
Recording a copy of commands and output
Date calculations
Miscellaneous
Debugging
Startup and shutdown sequences
Add-ons: packages and toolboxes
Object-oriented programming
Other interfaces
Efficiency/performance

 

Calling C
R
MATLAB

 

Bibliography

Index of R commands, variables, and symbols

Index of MATLAB commands, variables, and symbols