I want to update a List, using a For-statement. It doesn't work as I expect.
my data is like:
data = {{1, 11, 12, 13}, {1, 14, 15, 16}, {1, 17, 18, 19}, {2, 21, 22,
23}, {2, 24, 25, 26}, {2, 27, 28, 29}, {3, 31, 32, 33}, {3, 34,
35, 36}, {3, 37, 38, 39}};
set = {"A", "B", "C"};
The desired output is:
{{1, 11, 12, 13, A}, {1, 14, 15, 16, A}, {1, 17, 18, 19, A}, {2, 21,
22, 23, B}, {2, 24, 25, 26, B}, {2, 27, 28, 29, B}, {3, 31, 32, 33,
C}, {3, 34, 35, 36, C}, {3, 37, 38, 39, C}}
My idea was:
For[i = 2, i <= Length[set], i++,
Map[Append[#, set[[i]]] &, Select[data, #[[1]] == i &]]
];
But it does not give te output.
When I do the same
i = 1;
Map[Append[#, set[[i]]] &, Select[data, #[[1]] == i &]]
I get:
{{1, 11, 12, 13, "A"}, {1, 14, 15, 16, "A"}, {1, 17, 18, 19, "A"}}
Can somebody explain the difference and give me suggestion how to improve the FOR-statement (or a another solution te get the desired output.



Forgives no output. The documentation does not suggest that it would. – Szabolcs Nov 13 '20 at 13:46Table, or explain why you think you needFor) – Szabolcs Nov 13 '20 at 13:47