r - Change a part of a bigger matrix with a smaller one -
I have two metrics and I would like to change the small part of the small one.
So this is the first and this is the second matrix:
Large matrix:
matrix 1 = matrix (1: 36, nrow = 6, ncol = 6) Small matrix:
matrix 2 = matrix (1: 10, nrow = 2, ncol = 5) < / Pre> and should result in merging them: <,> [, 1] [, 2] [, 3] [, 4] [, 5] [, 6] [ 1,] 1 7 13 1 9 25 31 [2,] 2 8 14 20 26 32 [3,] 3 9 15 21 27 33 [4,] 1 3 5 7 9 34 [5,] 2 4 6 8 10 35 [6,] 6 12 18 24 30 36
Where only a part of the result matrix is smaller in the larger one in a special part
Here, the rules are not clear It looks like you have the matrix 1 Want to change the fourth and fifth line of matrix2 with column 1 to 5 . In that case: matrix new <- matrix 1 # has made a copy of the matrix 1 matrix [4: 5, -6] Specific part where a small number of seats sit 4 and 5 And columns are from 1 to 5. Therefore, I type the line index 4: 5 i.e. 4th and 5th, and column index -6 from [ to subset with. In Matrix 1, there are 6 columns, therefore, removes the column from -6 6 and leaves the 1: 5 column in the subset. Values based on index are replaced by matrix 2 values
Comments
Post a Comment