1
Installing and Running R and MATLAB
1.1 Obtaining and installing
R
R can be downloaded for free from The R Project Web site at http://www.r-project.org.
Follow the link to CRAN (Comprehensive R Archive Network) to download R. You must
first choose a CRAN mirror, i.e., one of the many Web sites around the world that keep
copies of the R software. It is probably best to choose one that is geographically close to
you.
Once you have chosen a mirror, you can choose which operating system (Linux, Mac
OS-X, or Windows) you use. Depending on your operating system, you may then have
further choices to make, such a s which dis tribution of Linux or which version of OS-X you
use. Note that the source code for R is also fre ely available for download from the same site.
When you actually run R on Windows or Mac OS-X, you will see a graphical user in-
terface like the one shown in Figure 1.1. T he interface primarily consists of the R Console
or Command window, where you can interactively type commands for R to interpret. The
standard comma nd pr ompt in R is >,” which means R is waiting for you to type a com-
mand. You c an try it out with some simple computations; for example, type 7*8 (and then
press Enter) to do a simple multiplication, or sqrt(exp(3)) to compute
e
3
. When you
run R on Linux in a terminal, you just get the command prompt, without the various menus
in the interface for OS-X and Windows.
You may wis h to use a much more compr ehensive, friendlier interface, especially if you
are coming to R from MATLAB. A very popular integrated development environment for
R, which has many of the same useful feature’s as MATLAB’s interface, is called RStudio;
it is available from http://www.rstudio.com. RStudio’s interface is shown in Figure 1.2.
If you are trying to ease your transition from MATLAB to R, you may seriously want to
consider installing and loading the pracma package, as it implements many functions which
behave nea rly equivalently with MATLAB routines; see Section 13.9 fo r information about
installing and loading packages.
MATLAB
MATLAB is available from The MathWorks, Inc . (http://www.mathworks.com). Pric-
ing and licensing information is available under their “Products & Services” link. There is a
very inexpensive option for students, and also special pricing for home and educational use.
It is also possible to obtain a trial version of the software. When you purchase MATLAB,
you will receive information for how to download and activate your copy.
MATLAB is available for all three popular operating sy stems (Linux, Mac OS-X, and
Windows).
When you run MATLAB, you will see a graphical user interface like the one shown in
Figure 1.3. The large region in the middle of the us er interface is the Command Window,
1
2 R and MATLAB
FIGURE 1 .1
The R graphical user interface in Mac OS-X.
Installing and Running R and MATLAB 3
FIGURE 1 .2
The RStudio graphical user interface in Ma c OS-X.
4 R and MATLAB
FIGURE 1 .3
The MATLAB graphical user interface in Mac OS-X.
where you can interactively type commands fo r MATLAB to interpret. The standard com-
mand prompt in MATLAB is >>,” which means MATLAB is waiting for you to type a
command. You can try it out with some simple computations; for example, type 7*8 (and
then press Enter) to do a simple multiplication, or sqrt(exp(3)) to compute
e
3
.
There are also many other things visible in the user interface. These include:
A file browser, listing the files in a given directory.
More information about a selected file.
The MATLAB workspace viewer, showing the variables that are currently defined.
1.2 Commands for getting help
Both platforms offer extensive built-in documentation. Depending on your operating sys-
tem, documentation may be available from menus or other items in the user interface.
Example commands are shown below, demonstrating how to access the various built-in
documentation systems from the command window.
R
help('eigen') Display documentation for the eigen function.

Get R and MATLAB now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.