I have a Table of values e.g.
{{x,y,z},{x,y,z},{x,y,z}…}
How do I replace the the "z" column with a List of values?
Answer
fun[u_, c_, r_] := Transpose@ReplacePart[Transpose[u], c -> r]
Example:
list = {{a, b, c}, {a, b, c}, {a, b, c}};
fun[list, 1, Range[3]]
yields:
{{1, b, c}, {2, b, c}, {3, b, c}}
This requires the replacement column be the same length (which I have assumed as intention) as final transpose will fail if this is not the case.
Comments
Post a Comment