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
andj,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 returnsNA
instead? I'm not asking fordiag(m) <- NA
command, I'm asking how to prevent computing those elements.
PS: This is reduced version of my problem