5
$\begingroup$

If I create a Tabular like this one, how can I use TransformColumns (or other command) to add a column that has the value of the row number i.e. {1,2,3,4...}

t = Tabular[{{1, 7, 4}, {4, 5, 6}, {7, 8, 9}}, {"a", "b", "c"}]
TransformColumns[t, "RowNum"-> ?]

so that the table becomes

{{1, 7, 4}, {4, 5, 6}, {7, 8, 9}}, {"a", "b", "c"}, {1, 2, 3}}?
$\endgroup$

2 Answers 2

3
$\begingroup$

Another idea is to insert the column:

t = Tabular[{{1, 7, 4}, {4, 5, 6}, {7, 8, 9}}, {"a", "b", "c"}];
InsertColumns[t, "RowNum" -> Range[Length[t]]]
$\endgroup$
4
$\begingroup$

Using ColumnwiseThread

t = Tabular[{{1, 7, 4}, {4, 5, 6}, {7, 8, 9}}, {"a", "b", "c"}];
TransformColumns[t, "RowNum" -> (ColumnwiseThread[Range@Length@t] &)]

row number

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.