Transpose a datatable

后端 未结 3 727
情话喂你
情话喂你 2020-12-22 08:31

I have the data table below. I would like to change the data table to transform the data table into the one next to it. How can I do this?

The reason why i would lik

3条回答
  •  忘掉有多难
    2020-12-22 09:18

    Create a new table, with reversed dimensions from what you previously had, and assign the previous columns to the new rows, and the old rows to the new columns.

    eg:

    oldCol1 -> newRow1
    oldCol2 -> newRow2
    oldCol3 -> newRow3
    oldCol4 -> newRow4
    oldRow1 -> newCol1
    oldCol2 -> newCol2
    oldvar[a][b] -> newvar[b][a]
    

    and the list goes on, assumming that you are going from

    col1 || col2 || col3 || col4
    row1 ||[a][b]||[c][d]||[e][f]
    row2 ||[g][h]||[i][j]||[k][l]
    

    to

    row1 || col1 || col2
    row2 ||[a][b]||[g][h]
    row3 ||[c][d]||[i][j]
    row4 ||[e][f]||[k][l]
    

提交回复
热议问题