8
a = {{-800, 1712}, {-801, 1713}, {-806, 1832}}
TableForm[a]
b = a[[All, 2]] - Min[a[[All, 2]]]

How do I make a new matrix (list) whic looks like this

-800  1712 0
-801  1713 1
-806  1832 120

The 3rd column, takes the difference between the value from the 2nd column and it's minimum of the whole 2nd column.

I tried to Join the two, but with no success.

Thanks.

Chen Stats Yu
  • 4,986
  • 2
  • 24
  • 50

1 Answers1

13

Perhaps I've missed something, but you seem to just want to append a vector (which you have already calculated) to a matrix.

Documentation for Append[] shows how to do it:

enter image description here

For your case since you already have a and b:

MapThread[Append, {a, b}] // MatrixForm

enter image description here

A different approach enables you to join matrixes to make longer rows:

The following makes a 2 column matrix from your b

b2 = Transpose[{b, b}];
b2 // MatrixForm

enter image description here

The documentation for Join[] shows the way to do what you asked for in your comment:

enter image description here

Note that the 2 at the end of the Join[] operates as a level specification.

For your case:

Join[a, b2, 2];
% // MatrixForm

enter image description here

Jagra
  • 14,343
  • 1
  • 39
  • 81