This is pretty well documented in the docs for upper.tri
.
Amat[upper.tri(Amat)] <- NA
Amat
# [,1] [,2] [,3] [,4]
# [1,] 1 NA NA NA
# [2,] 0 1 NA NA
# [3,] 0 0 1 NA
# [4,] 0 0 0 1
Of course, Amat[lower.tri(Amat)] <- NA
would do the same for converting the lower triangle to NA
s.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…