Skip to content
Prev 244203 / 398506 Next

Efficient way to use data frame of indices to initialize matrix

I have a data frame with three columns, x, y, and a.  I want to create a matrix from these values such that for matrix m:
m[x,y] == a

Obviously, I can go row by row through the data frame and insert the value a at the correct x,y location in the matrix.  I can make that slightly more efficient (perhaps), by doing something like this:
But I feel that there must be a more efficient, or at least more elegant way to do this.

--
Gene