Regular matrix indices and naming

A matrix is a table of numbers.
Typical matrix indexing: mat[i,j], mat[1:2,] etc\\

A matrix can have row and column names
Indexing with row and column names: mat["a","B"]
Explanation
Example: dimnames(mat)<-list(c("a","b"),c("1","2","3"))
Details
% the main body of text underlying the slide goes here -- the percentage sign is a comment
\begin{defn}
A {\bf matrix} is a (two-dimensional) table of numbers, indexed by row and column numbers.
\end{defn}
\begin{notes}
Note that a matrix can also have row and column names so that the matrix can be indexed by its names rather than numbers.
\end{notes}
Examples
% \bf make the example bold -- the curly braces limit the extent of the bold
\begin{xmpl}
 Consider a matrix with 2 rows and 3 columns. Consider extracting first element (1,2), then all of line 2 and then columns 2-3 in an R session:

\begin{lstlisting}
mat<-matrix(1:6,ncol=3)
mat
     [,1] [,2] [,3]
[1,] 1 3 5
[2,] 2 4 6

mat[1,2]
[1] 3

mat[2,]
[1] 2 4 6

mat[,2:3]
     [,1] [,2]
[1,] 3 5
[2,] 4 6
\end{lstlisting}

Next, consider the same matrix, but give names to the rows and columns.
The rows will get the names "a" and "b"
and the columns will be named "A", "B" and "C".
% \begin{verbatim} is used to start a "verbatim" environment

The entire R session could look like this:
\begin{lstlisting}
mat<-matrix(1:6,ncol=3)
dimnames(mat)<-list(c("a","b"),c("A","B","C"))
mat
  A B C
a 1 3 5
b 2 4 6

mat["b",c("B","C")]
B C
4 6

\end{lstlisting}
\end{xmpl}