peter leonard wrote:
> I have a  4x4 matrix  named 'lookup' with the following values:
[...] 
> I then create a new empty matrix named 'dd' with specfic row and col 
> names :
> 
>   1   3   4   3    3   1
> 1 NA NA NA NA NA NA
> 2 NA NA NA NA NA NA
> 3 NA NA NA NA NA NA
> 4 NA NA NA NA NA NA
> 3 NA NA NA NA NA NA
> 2 NA NA NA NA NA NA
> 1 NA NA NA NA NA NA
> 
> I want to be able populate the cells in 'dd' using 'lookup' based on the 
> specified rownames and colnames of 'dd'. For example, the cell in 'dd' 


If an R matrix is subscripted by an n by 2 matrix of row,column index
pairs then the result is a vector of length n with the corresponding values taken from that matrix.  Thus, suppose:

   rn <- c(1:4,3:1)
   cn <- c(1,3,4,3,3,1)

Then dd strung out into a vector is:

   dd.vec <- lookup[as.matrix(expand.grid(rn,cn))]

and reshaping this vector into a matrix gives:

   dd <- matrix(result.vec,nr=length(rn))


