How to efficiently generate lower triangle indices of a symmetric matrix
问题 I need to generate lower triangle matrix indices (row and columns pairs). The current implementation is inefficient (memory wise) specially when symmetric matrix gets big (more than 50K rows). Is there a better way? rows <- 2e+01 id <- which(lower.tri(matrix(, rows, rows)) == TRUE, arr.ind=T) head(id) # row col # [1,] 2 1 # [2,] 3 1 # [3,] 4 1 # [4,] 5 1 # [5,] 6 1 # [6,] 7 1 回答1: Here's another approach: z <- sequence(rows) cbind( row = unlist(lapply(2:rows, function(x) x:rows), use.names =