Skip to content
Prev 42646 / 398506 Next

Matrix indexes

On Mon, 12 Jan 2004, W. Beldman wrote:

            
Not about `matrix indexing', which may have confused you.  Matrix indexing
of a matrix is when the index is a two-column matrix of row-column number
pairs.
No, omitted.
So this is vector indexing by a logical vector.  It does no harm to try 
it:
[,1] [,2] [,3] [,4]
[1,]    1    5    9   13
[2,]    2    6   10   14
[3,]    3    7   11   15
[4,]    4    8   12   16
[,1]  [,2]  [,3]  [,4]
[1,] TRUE FALSE FALSE FALSE
[2,] TRUE  TRUE FALSE FALSE
[3,] TRUE  TRUE  TRUE FALSE
[4,] TRUE  TRUE  TRUE  TRUE
[1]  1  2  3  4  6  7  8 11 12 16

so the result is the lower triangle read out as a vector in the usual
first-index-varies fastest order.
Yes. Again, simple example:
[,1] [,2] [,3] [,4]
[1,]    1    1    0    0
[2,]    0    0    0    0
[3,]    1    1    0    0
[4,]    0    0    0    0
[,1] [,2]
[1,]    1    5
[2,]    3    7


And finally an example of matrix indexing
[,1] [,2]
[1,]    1    1
[2,]    2    3
[1]  1 10
Some of the books in the FAQ, notably `S Programming', will help a lot.