List of Figures |
|
xiii | |
List of Tables |
|
xv | |
Preface |
|
xvii | |
About the Author |
|
xxi | |
1 Installing and Running R and MATLAB |
|
1 | (8) |
|
1.1 Obtaining and installing |
|
|
1 | (3) |
|
1.2 Commands for getting help |
|
|
4 | (2) |
|
|
6 | (1) |
|
|
6 | (1) |
|
|
6 | (3) |
2 Getting Started: Variables and Basic Computations |
|
9 | (10) |
|
|
9 | (1) |
|
2.2 Assignment statements |
|
|
10 | (1) |
|
|
11 | (3) |
|
|
14 | (1) |
|
|
15 | (1) |
|
|
16 | (1) |
|
2.7 Strange variable names in R |
|
|
16 | (1) |
|
|
17 | (2) |
|
|
17 | (1) |
|
|
18 | (1) |
3 Matrices and Vectors |
|
19 | (22) |
|
|
19 | (1) |
|
|
19 | (3) |
|
|
22 | (3) |
|
|
25 | (2) |
|
3.5 Working with matrices |
|
|
27 | (4) |
|
3.6 Reshaping matrices, and higher-dimensional arrays |
|
|
31 | (2) |
|
|
33 | (1) |
|
3.8 Names with vectors and matrices/arrays |
|
|
33 | (6) |
|
3.8.1 R: names for vector/matrix elements and matrix rows/columns |
|
|
33 | (2) |
|
|
35 | (2) |
|
|
37 | (2) |
|
|
39 | (2) |
4 Matrix/Vector Calculations and Functions |
|
41 | (14) |
|
4.1 Applying a function to rows or columns of a matrix |
|
|
41 | (1) |
|
4.2 Applying a function to all elements of a matrix |
|
|
42 | (1) |
|
4.3 Linear algebra calculations with vectors and matrices |
|
|
43 | (3) |
|
4.4 Statistical calculations |
|
|
46 | (3) |
|
4.5 Vectorized logical tests |
|
|
49 | (1) |
|
|
50 | (5) |
5 Lists and Cell Arrays |
|
55 | (10) |
|
5.1 Creating lists and cell arrays |
|
|
55 | (1) |
|
5.2 Using lists and cell arrays |
|
|
56 | (2) |
|
5.3 Applying functions to all elements of lists and cell arrays |
|
|
58 | (2) |
|
5.4 Converting other data types to lists and cell arrays |
|
|
60 | (1) |
|
5.4.1 All values in a numeric vector or matrix |
|
|
60 | (1) |
|
5.4.2 Matrix, by columns or rows |
|
|
61 | (1) |
|
5.5 Converting lists and cell arrays to other data types |
|
|
61 | (4) |
|
5.5.1 Set of vectors to a single vector |
|
|
61 | (1) |
|
5.5.2 Set of vectors to matrix |
|
|
62 | (1) |
|
5.5.3 Set of sets to matrix |
|
|
63 | (1) |
|
5.5.4 Set of strings to a set of numeric vectors |
|
|
63 | (2) |
6 Flow Control |
|
65 | (12) |
|
6.1 Conditional ("if") statements |
|
|
65 | (2) |
|
|
67 | (2) |
|
|
69 | (2) |
|
|
71 | (1) |
|
6.5 Breaking out of loops |
|
|
72 | (1) |
|
|
73 | (3) |
|
6.7 "ifelse" statements in R |
|
|
76 | (1) |
7 Running Code from Files: Scripts |
|
77 | (6) |
|
7.1 Current working directory |
|
|
77 | (1) |
|
7.2 The MATLAB search path |
|
|
78 | (1) |
|
7.3 Executing code from a file |
|
|
78 | (1) |
|
7.4 Creating a new script document in the editor |
|
|
79 | (1) |
|
7.5 Comments in script files |
|
|
80 | (1) |
|
7.6 Executing code from the editor window |
|
|
81 | (1) |
|
7.7 Summary of differences |
|
|
82 | (1) |
8 Writing Your Own Functions |
|
83 | (16) |
|
|
83 | (6) |
|
|
83 | (2) |
|
|
85 | (1) |
|
8.1.3 Environments and variable scope |
|
|
85 | (2) |
|
|
87 | (1) |
|
|
88 | (1) |
|
|
89 | (7) |
|
8.2.1 Inline and anonymous functions |
|
|
89 | (1) |
|
|
89 | (2) |
|
|
91 | (2) |
|
8.2.4 Environments and variable scope |
|
|
93 | (1) |
|
|
94 | (1) |
|
|
95 | (1) |
|
|
96 | (1) |
|
8.3 Summary of main differences |
|
|
96 | (3) |
9 Probability and Random Numbers |
|
99 | (8) |
|
9.1 Basic random values, permutations, and samples |
|
|
99 | (2) |
|
|
101 | (1) |
|
9.3 Random variates from probability distributions |
|
|
102 | (2) |
|
9.4 PDFs, CDFs, and inverse CDFs |
|
|
104 | (3) |
10 Graphics |
|
107 | (30) |
|
10.1 Creating, selecting, and closing figure windows |
|
|
107 | (1) |
|
|
107 | (1) |
|
10.1.2 Listing and selecting windows |
|
|
108 | (1) |
|
|
108 | (1) |
|
10.2 Basic 2-D scatterplots |
|
|
108 | (3) |
|
10.3 Adding additional plots to a figure |
|
|
111 | (1) |
|
|
111 | (1) |
|
10.5 Logarithmic axis scales |
|
|
112 | (1) |
|
|
112 | (1) |
|
10.7 Plotting multiple data sets simultaneously |
|
|
112 | (2) |
|
10.8 Axis labels and figure titles |
|
|
114 | (1) |
|
10.9 Adding text to figures |
|
|
114 | (1) |
|
10.10 Greek letters and mathematical symbols |
|
|
115 | (1) |
|
|
116 | (1) |
|
|
117 | (2) |
|
10.13 Size and font adjustments |
|
|
119 | (1) |
|
|
120 | (1) |
|
|
121 | (1) |
|
10.16 Image plots and contours |
|
|
122 | (4) |
|
|
126 | (1) |
|
|
126 | (2) |
|
10.19 Multiple subplots in one figure |
|
|
128 | (3) |
|
|
131 | (2) |
|
10.21 Other types of plots |
|
|
133 | (2) |
|
10.22 Final notes about graphics |
|
|
135 | (2) |
11 Numerical Computing |
|
137 | (10) |
|
|
137 | (1) |
|
11.1.1 Something to watch out for |
|
|
138 | (1) |
|
11.2 Univariate optimization |
|
|
138 | (1) |
|
11.3 Multivariate optimization |
|
|
139 | (1) |
|
11.4 Numerical integration |
|
|
140 | (1) |
|
|
140 | (2) |
|
11.5.1 Piecewise linear interpolation |
|
|
140 | (1) |
|
11.5.2 Polynomial fitting |
|
|
141 | (1) |
|
|
142 | (1) |
|
11.6 Differential equations |
|
|
142 | (5) |
12 File Input and Output |
|
147 | (18) |
|
|
147 | (1) |
|
12.2 Reading a table of numbers |
|
|
148 | (4) |
|
12.2.1 Subsets of a data file |
|
|
151 | (1) |
|
12.3 Reading numeric data with a different comment character |
|
|
152 | (1) |
|
12.4 Reading numbers from a file where different lines have varying numbers of values |
|
|
153 | (3) |
|
12.5 Reading numbers and strings |
|
|
156 | (3) |
|
12.6 Reading the raw character data in, a line at a time |
|
|
159 | (1) |
|
12.7 Writing a table of numbers |
|
|
159 | (1) |
|
12.8 Writing a set of strings |
|
|
160 | (1) |
|
12.9 Saving and loading variables in binary format |
|
|
161 | (1) |
|
|
162 | (1) |
|
|
163 | (1) |
|
|
163 | (2) |
13 Miscellaneous |
|
165 | (12) |
|
13.1 Working with variables |
|
|
165 | (1) |
|
|
166 | (2) |
|
|
168 | (1) |
|
13.4 Recording a copy of commands and output |
|
|
169 | (1) |
|
|
169 | (1) |
|
|
170 | (1) |
|
|
171 | (1) |
|
13.8 Startup and shutdown sequences |
|
|
172 | (1) |
|
13.9 Add-ons: packages and toolboxes |
|
|
173 | (1) |
|
13.10 Object-oriented programming |
|
|
174 | (1) |
|
|
174 | (1) |
|
13.12 Efficiency/performance |
|
|
175 | (2) |
14 Calling C |
|
177 | (22) |
|
|
178 | (10) |
|
14.1.1 Example and overview |
|
|
178 | (3) |
|
14.1.2 Printing, warnings, and errors |
|
|
181 | (1) |
|
|
182 | (3) |
|
14.1.4 More advanced features |
|
|
185 | (3) |
|
|
188 | (11) |
|
14.2.1 Example and overview |
|
|
188 | (4) |
|
14.2.2 Printing, warnings, and errors |
|
|
192 | (1) |
|
|
192 | (7) |
Bibliography |
|
199 | (2) |
Index of R commands, variables, and symbols |
|
201 | (6) |
Index of MATLAB commands, variables, and symbols |
|
207 | |