Given some lists
lstRow1 = {{"C1", "C2", "C3"}, {1, 2, 3}};
lstRow2 = {{"C2", "D1", "D2"}, {4, 5, 6}};
lstRow3 = {{"C1", "D2", "D3"}, {7, 8, 9}};
lstRow4 = {{}, {}};
lstRow5 = {{"D1", "D2", "E1"}, {10, 11, 12}};
lstRow6 = {{}, {}};
lstHead = {{"C1", "H1"}, {"C2", "H1"}, {"C3", "H1"}, {"D1",
"H2"}, {"D2", "H2"}, {"D3", "H2"}, {"E1", "H3"}};
how to build a sparse arrary like this:
lstSparse = {
{"H1", "0", "0", "H2", "0", "0", "H3"},
{"C1", "C2", "C3", "D1", "D2", "D3", "E1"}, {1, 2, 3, 0, 0, 0,
0}, {0, 4, 0, 5, 6, 0, 0}, {7, 0, 0, 0, 8, 9, 0}, {0, 0, 0, 0, 0,
0, 0}, {0, 0, 0, 10, 11, 0, 12}, {0, 0, 0, 0, 0, 0, 0}};
or ZEROs could be replaced by blank string, to be like this. $$\left( \begin{array}{ccccccc} \text{H1} & \text{0} & \text{0} & \text{H2} & \text{0} & \text{0} & \text{H3} \\ \text{C1} & \text{C2} & \text{C3} & \text{D1} & \text{D2} & \text{D3} & \text{E1} \\ 1 & 2 & 3 & 0 & 0 & 0 & 0 \\ 0 & 4 & 0 & 5 & 6 & 0 & 0 \\ 7 & 0 & 0 & 0 & 8 & 9 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 10 & 11 & 0 & 12 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ \end{array} \right) \to \left( \begin{array}{ccccccc} \text{H1} & \text{} & \text{} & \text{H2} & \text{} & \text{} & \text{H3} \\ \text{C1} & \text{C2} & \text{C3} & \text{D1} & \text{D2} & \text{D3} & \text{E1} \\ 1 & 2 & 3 & \text{} & \text{} & \text{} & \text{} \\ \text{} & 4 & \text{} & 5 & 6 & \text{} & \text{} \\ 7 & \text{} & \text{} & \text{} & 8 & 9 & \text{} \\ \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} \\ \text{} & \text{} & \text{} & 10 & 11 & \text{} & 12 \\ \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} \\ \end{array} \right)$$