I want to insert a set of n values expressed as a vector into the corresponding set of places in the matrix. The real application includes inserting a set of sea surface temperature values n into the image of the region, which is presented in the form of a grid with a size nkn x ncol> n, for which I have identified n water pixels that should receive temperature values, The problem I'm faced, lies in the fact that the temperature values are ordered as if they were from the main matrix of the column, and not to order the rows, to index the grid R.
Here is an example of a toy that I mean.
> grid <- matrix(0,4,4) > grid # define the base grid [,1] [,2] [,3] [,4] [1,] 0 0 0 0 [2,] 0 0 0 0 [3,] 0 0 0 0 [4,] 0 0 0 0 > temps <- c(9,9,9,9,9) # we have 5 temperature values > locs <- c(2,3,4,6,7) # locations in the base grid that are water > grid[locs] <- temps # not really what I want - substitution in row-major order > grid [,1] [,2] [,3] [,4] [1,] 0 0 0 0 [2,] 9 9 0 0 [3,] 9 9 0 0 [4,] 9 0 0 0
The desired result will be sooner:
[,1] [,2] [,3] [,4] [1,] 0 9 9 9 [2,] 0 9 9 0 [3,] 0 0 0 0 [4,] 0 0 0 0
I believe that I could play with the transpose of the grid by performing a permutation and then moving it back, but I think that would be a better way to approach this problem.