Selecting specific elements from a matrix all at once

后端 未结 3 566
旧巷少年郎
旧巷少年郎 2021-02-05 23:53

Is there a way I can select a bunch of prespecified elements all at once from a matrix? Specifically, suppose I have the following matrix:

      58        59             


        
3条回答
  •  不知归路
    2021-02-06 00:48

    A solution to your specific situation would be to select the sub-matrix and use the diag function:

    R> diag(x[-ncol(x),-1])
    [1] 3.772139 3.755554 5.999409 3.810169 3.796884
    

提交回复
热议问题