在上/下三角形中选择相应的单元格 [英] select the corresponding cell in the upper/lower triangle
本文介绍了在上/下三角形中选择相应的单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
想象一下我们有这样的东西:
Imagine we have something like:
mat <- matrix(rep(1,25), nrow = 5)
mat
# [,1] [,2] [,3] [,4] [,5]
#[1,] 1 1 1 1 1
#[2,] 1 1 1 1 1
#[3,] 1 1 1 1 1
#[4,] 1 1 1 1 1
#[5,] 1 1 1 1 1
如果我在矩阵中选择一个单元格,即mat[1]
,我如何系统地选择对角三角形中的相应单元格.即mat[25]
If i select a cell in the matrix i.e. mat[1]
, how can i systematically select the corresponding cell in the opposite triangle. i.e. mat[25]
我也可以选择单元格mat[21]
,然后我想要mat[5]
for instance I could also select cell mat[21]
then I would want mat[5]
推荐答案
让i
作为您的1
或21
,您可以这样做:
Let i
be your 1
or 21
, you could do:
mat[length(mat) - i + 1]
或
rev(mat)[i]
这篇关于在上/下三角形中选择相应的单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文