5
Lists and Cell Arrays
In both R
and MATLAB, a matrix or vector can only hold a set of values of the same type, for example floating-point values, integers, logical values, characters, etc. Sometimes it is convenient to build a more general object which can contain values of different types. Both platforms provide ways of doing this. In R,
lists are used, while in MATLAB, cell arrays are used (but also see MATLAB structs in Section 3.8.3). As with matrices and vectors, in R,
a list is fundamentally a vector object (from which you can build matrices), while in MATLAB a cell array is fundamentally a matrix (which may be equivalent to a vector if it happens to have only one row or column).
5.1 Creating lists and cell arrays
Let us create ...
Get R and MATLAB now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.