Consider the following table:
tabb = Table[RandomReal[{0, 100}, 100], {i, 1, 10, 1}];
How to replace its kth column (say, the 52th column) by the column
col=Table[{i},{i,1,10,1}]?
Consider the following table:
tabb = Table[RandomReal[{0, 100}, 100], {i, 1, 10, 1}];
How to replace its kth column (say, the 52th column) by the column
col=Table[{i},{i,1,10,1}]?
I assume your data is just made up for an example, but just for reference, you can do this:
tabb = RandomReal[{0, 100}, {10, 100}]
I also assume that you don't intend to replace numbers with lists, so let's simplify your new column:
col = Range@10
Now we have a couple of options. If you want to mutate in place, you can use Set directly:
tabb2[[All, 52]] = col
If you want a new structure, one option is SubsetMap:
newtabb = SubsetMap[col &, tabb, {All, 52}]
Another is MapThread:
newtabb = MapThread[ReplacePart[#1, 52 -> #2] &, {tabb, col}]
Another is just ReplacePart with patterns:
newtabb = ReplacePart[tabb, {row_, 52} :> col[[row]]]
To clearly see the results it is better to use symbolic arrays and vectors. And dimensions on the order of 100 are excessive in a minimal example.
Clear["Global`*"]
(Format[#[i__]] := Subscript[#, Row[{i}]]) & /@ {a, b};
(tabb = Array[b, {5, 8}]) // MatrixForm
col = Array[Style[a[#], Red] &, Length@tabb];
As Syed indicated, to replace column 3
tabb[[All, 3]] = col;
tabb // MatrixForm
tabb[[All, 52]] = col. Since Mathematica doesn't differentiate between column and row vectors, you might just want to have a plain list there. – Syed Jun 28 '22 at 15:13