compute only upper triangle of matrix
问题 I have vector: v1 = c(1,2,3) From this vector I want to create matrix where element on i,j position will be sum of vector members on i,j positions: [,1] [,2] [,3] [1,] 2 3 4 [2,] 3 4 5 [3,] 4 5 6 Questions : i,j and j,i is the same, so there is no reason to compute it 2x for better performance. How to achieve this? How to create also variant which will not compute elements if i == j and simply returns NA instead? I'm not asking for diag(m) <- NA command, I'm asking how to prevent computing