Mathematica HowTo
How to | Work with Nested Lists
Nested lists are lists within a list; they are the principal structure for data in Mathematica and allow for high dimension arrays and ragged data sets as well as common uses such as matrices.
Create a list of lists to work with:
 Out[1]=
Matrices in Mathematica are represented as nested lists. Note that each row corresponds to a sublist in the nested list:
 Out[2]//MatrixForm=
Use [[]], the short form of the Part function, to get the second row:
 Out[3]=
From row 2, get element 3:
 Out[4]=
Get element 3 from each row:
 Out[5]=
Use Flatten to remove the nesting:
 Out[6]=
Display the flattened data as a column:
 Out[7]//MatrixForm=
For comparison, to display the flattened data as a row, add {}:
 Out[8]//MatrixForm=

You can operate on the individual sublists of a nested list or on the nested list as a whole.
Set up a dataset:
 Out[9]=
 Out[10]//MatrixForm=
Most functions map over each sublist within a nested list.
Create four plots from the rows in the dataset:
 Out[11]=
Most descriptive statistics functions operate by columns.
Take the mean by column:
 Out[12]=
Get the mean of the all of the numbers by flattening the list:
 Out[13]=

Create a doubly nested list:
 Out[14]//MatrixForm=
Mean now lists the means by each individual nested sublist:
 Out[15]//MatrixForm=
Use Flatten to obtain the mean of the entire dataset:
 Out[16]=