I want to add a number to each sublist
For example add 10 so it looks like:
newlist = {{1,2,3,10}, {4,5,6,10}, {7,8,9,10}}
I have looked Insert, Map etc but can’t seem to grasp how to do it.
In actuality I will want to add a unique ID (ie each unique ID is different like a primary key) to each sublist
so it would be
list = {{1,2,3,unique ID},{4,5,6, unique ID},{7,8,9, unique ID}}
The unique ID would be most likely by a function I suppose.
Thanks so much! I spent a couple hours trying to figure this out. My error was when I used Append on the list it added it to the list and I did not get that Map effectively does that to each sublist.
Append[list, 10]
{{1, 2, 3}, {3, 4, 5}, 10}
But by using Map it did that over the sublists. My next challenge will be to add a unique number to the lists.
Very nice! I am trying to do this all in Mathematica vs SQL and or Excel. So, this really helps. Otherwise I always fall back and never progress with Mathematica.
If you original array is not ragged (unequal lengths of sublists), then it is equivalent to adding row / column (a vector) to a matrix. Consider initial data:
m = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
v = {a, b, c};
Thank you all for the responses! This gives me a good framework for the project. CreateUUID is very helpful since that is what I need to do the list I have. All the suggestions though give me a strategies for this type of problem.