Re: [R] expand a matrix

2022-09-05 Thread Andrew Simmons
You can specify multiple indexes to replace at once, so you can avoid a for loop entirely like this: M <- matrix(nrow = 10, ncol = 10) M[1:4, 5: 6] <- M[5: 6, 1:4] <- m[1, 2] M[1:4,7] <- M[ 7, 1:4] <- m[1, 3] M[1:4, 8:10] <- M[8:10, 1:4] <- m[1, 4] M[5:6,7] <- M[ 7, 5:6] <- m[2, 3] M[5:

[R] expand a matrix

2022-09-05 Thread Jinsong Zhao
Hi there, I have a matrix likes: > m [,1] [,2] [,3] [,4] [1,] NA123 [2,]1 NA65 [3,]26 NA4 [4,]354 NA I hope to expand it to 10 by 10 matrix, M, likes: > M [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] NA NA NA