x***x 发帖数: 3401 | 1 I have a matrix M and a array L. L contains a list of integers.
The integers are the indexes of the row numbers in the matrix M.
I want to make a new matrix N where the ith row corresponds to the L[i]th
row of the M matrix.
Is there an easy way of doing this?
I can only think of a loop with rbind() function. Any other simpler ideas or
functions?
Thanks | x***x 发帖数: 3401 | 2 举个例子好懂一点
比如L=(3,5,2,7)
那么我需要取M的3, 5, 2, 7行作为N的1, 2, 3, 4行.
谢谢 | m****r 发帖数: 237 | 3 Just use
N=M[L,]
I think that will do it
【在 x***x 的大作中提到】 : 举个例子好懂一点 : 比如L=(3,5,2,7) : 那么我需要取M的3, 5, 2, 7行作为N的1, 2, 3, 4行. : 谢谢
| m****r 发帖数: 237 | 4 and r u sure L is an array instead of vector??
or
【在 x***x 的大作中提到】 : I have a matrix M and a array L. L contains a list of integers. : The integers are the indexes of the row numbers in the matrix M. : I want to make a new matrix N where the ith row corresponds to the L[i]th : row of the M matrix. : Is there an easy way of doing this? : I can only think of a loop with rbind() function. Any other simpler ideas or : functions? : Thanks
| x***x 发帖数: 3401 | 5 oh, right, Thanks!
【在 m****r 的大作中提到】 : Just use : N=M[L,] : I think that will do it
|
|