# Inserting columns multiple times

I think this question is very simple and will be closed, but I'm left with doubts.

transform = CoordinateTransformData["Polar" -> "Cartesian", "Mapping"];
{p1, p2, p3, p4, p5, p6} =
transform[{2 Sqrt[3], # Degree}] & /@ Most[Subdivide[360, 6] + 30] //
N


$\left( \begin{array}{cc} 3. & 1.73205 \\ 0. & 3.4641 \\ -3. & 1.73205 \\ -3. & -1.73205 \\ 0. & -3.4641 \\ 3. & -1.73205 \\ \end{array} \right)$

How could I apply the insert function to get this result?

Join[{{3., 1.7320508075688772, 0}, {0., 3.4641016151377544, 0}, {-3.,
1.7320508075688772, 0}, {-3., -1.7320508075688772,
0}, {0., -3.4641016151377544, 0},
{3., -1.7320508075688772, 0}}, {{3., 1.7320508075688772,
15}, {0., 3.4641016151377544, 15}, {-3., 1.7320508075688772,
15}, {-3., -1.7320508075688772, 15}, {0., -3.4641016151377544, 15},
{3., -1.7320508075688772, 15}}]


$\left( \begin{array}{ccc} 3. & 1.73205 & 0 \\ 0. & 3.4641 & 0 \\ -3. & 1.73205 & 0 \\ -3. & -1.73205 & 0 \\ 0. & -3.4641 & 0 \\ 3. & -1.73205 & 0 \\ 3. & 1.73205 & 15 \\ 0. & 3.4641 & 15 \\ -3. & 1.73205 & 15 \\ -3. & -1.73205 & 15 \\ 0. & -3.4641 & 15 \\ 3. & -1.73205 & 15 \\ \end{array} \right)$

• Have you tried PadRight? Dec 20, 2016 at 11:13
– user45104
Dec 20, 2016 at 11:47
• I think there no solution with Insert only. Otherwise there are plenty of solutions. I would do something like this : Join[Insert[#, 0, -1] & /@ {p1, p2, p3, p4, p5, p6}, Insert[#, 15, -1] & /@ {p1, p2, p3, p4, p5, p6}] Dec 20, 2016 at 11:58
• Dec 21, 2016 at 22:28

Using lowriniak's comment:

transform = CoordinateTransformData["Polar" -> "Cartesian", "Mapping"];
{p1, p2, p3, p4, p5, p6} =
transform[{2 Sqrt[3], # Degree}] & /@ Most[Subdivide[360, 6] + 30] //
N


$\left( \begin{array}{cc} 3. & 1.73205 \\ 0. & 3.4641 \\ -3. & 1.73205 \\ -3. & -1.73205 \\ 0. & -3.4641 \\ 3. & -1.73205 \\ \end{array} \right)$

Through PadRight function:

Join[PadRight[{p1, p2, p3, p4, p5, p6}, {6, 3}],
PadRight[{p1, p2, p3, p4, p5, p6}, {6, 3}, {15}]]


$\left( \begin{array}{ccc} 3. & 1.73205 & 0 \\ 0. & 3.4641 & 0 \\ -3. & 1.73205 & 0 \\ -3. & -1.73205 & 0 \\ 0. & -3.4641 & 0 \\ 3. & -1.73205 & 0 \\ 3. & 1.73205 & 15 \\ 0. & 3.4641 & 15 \\ -3. & 1.73205 & 15 \\ -3. & -1.73205 & 15 \\ 0. & -3.4641 & 15 \\ 3. & -1.73205 & 15 \\ \end{array} \right)$

Behold ArrayFlatten

pn = {p1, p2, p3, p4, p5, p6};

ArrayFlatten[{{pn, 0}, {pn, 15}}] // MatrixForm


$\left( \begin{array}{ccc} 3. & 1.73205 & 0 \\ 0. & 3.4641 & 0 \\ -3. & 1.73205 & 0 \\ -3. & -1.73205 & 0 \\ 0. & -3.4641 & 0 \\ 3. & -1.73205 & 0 \\ 3. & 1.73205 & 15 \\ 0. & 3.4641 & 15 \\ -3. & 1.73205 & 15 \\ -3. & -1.73205 & 15 \\ 0. & -3.4641 & 15 \\ 3. & -1.73205 & 15 \\ \end{array} \right)$

Also

Distribute[{{0, 15}, pn}, List, List, List, Append[#2, #] &] // MatrixForm


or

Join @@ Outer[Append[#2, #] &,  {0, 15}, pn, 1] // MatrixForm


Note: you can use Insert[#2, #, -1] & instead of Append[#2, #] in the above.