To build a matrix of differences between the elements of a vector, you could simply get the vector in column form and substract its transposed (row) vector. Similarly to what you would do in matrix multiplication but by subtracting instead of multiplying:
--------1-------2-------3------4
1---(1-1) (1-2)
2---(2-1) ... et cetera
3---(3-1)
4---(4-1)
Giving as a result the matrix of differences between the elements of the vector.
However, this very simple operation is never defined in basic introductory courses or texts to matrix algebra. Is there a name for this operation, like "transposed vector subtraction" or "col-row vector subtraction"?. Why isn't this very simple operation defined in general matrix algebra?
Moreover, not all software packages allow it. For instance, I can perform it in MatLab simply by coding:
X - X' ;
where X is a column vector and X' is its transpose
(while, if I wanted to get the element-by-element difference, the code should be: X .- X')
...But, if I do the same in R, it simply doesn't do it. I had to create a for-loop to code it.