Anonymous prefix lambda. Takes column numbers for "transposition" as right argument and prompts via stdin for filename of table.
{(t[;⍵~⍨⍳≢⍉t]⌿⍨≢⍵),(⍪,⍨⍵⍴⍨≢),t[;⍵]⊣t←↑(∊∘⎕D⊆⊢)¨⊃⎕NGET⍞1}
Try it online!
{…} "dfn"; right argument (column numbers) is ⍵:
⍞1 prompt for file name from stdin and juxtapose with 1 (indicating that we want a list of strings)
["tpose",1]
⎕NGET get the native file's (content,encoding,newline)
[["0 030915 10 20 30 40","1 030915 15 7 49 2"],"UTF-8-NOBOM",[10]]
⊃ pick the first of those (content)
["0 030915 10 20 30 40","1 030915 15 7 49 2"]
(…)¨ apply the following tacit function to each line:
∊ the characters that are members
∘ of
⎕D the set of digits
[[1,0,1,1,1,1,1,1,0,1,1,0,1,1,0,1,1,0,1,1],[1,0,1,1,1,1,1,1,0,1,1,0,1,0,1,1,0,1]]
⊆ indicate the sub-partitions of
⊢ the line
[["0","030915","10","20","30","40"],["1","030915","15","7","49","2"]]
↑ up the rank by mixing the list (rank 1) of lists into a matrix (rank 2)
[["0","030915","10","20","30","40"],
["1","030915","15","7" ,"49","2" ]]
t← assign that to t (for table)
⊣ discard that in favour of
t[;⍵] all rows of the subset of columns of t enumerated in the argument
[["10","20","30","40"],
["15","7" ,"49","2" ]]
, ravel (flatten that)
["10","20","30","40","15","7","49","2"]
(…) apply the following tacit function to that:
≢ the tally of elements
8
⍵⍴⍨ use that to reshape the number of columns to be "transposed"
[3,4,5,6,3,4,5,6]
,⍨ to that, append
⍪ the table-fied (made into single-column table) argument (the "transposed" columns)
[[3,"10"],
[4,"20"],
[5,"30"],
[6,"40"],
[3,"15"],
[4,"7" ],
[5,"49"],
[6,"2" ]]
(…), prepend the following:
≢⍵ the tally of columns to be "transposed"
4
…⌿⍨ use that to vertically replicate the rows of…
t[;…] all rows of the following columns of the table:
⍉t transpose the table
[["0" ,"1" ],
["030915","030915"],
["10" ,"15" ],
["20" ,"7" ],
["30" ,"49" ],
["40" ,"2" ]]
≢ the tally of rows
6
⍳ ɩndices until that
[1,2,3,4,5,6]
⍵~⍨ except the "transposed" column numbers
[1,2]
[["0","030915"],
["1","030915"]]
[["0","030915"],
["0","030915"],
["0","030915"],
["0","030915"],
["1","030915"],
["1","030915"],
["1","030915"],
["1","030915"]]
[["0","030915",3,"10"],
["0","030915",4,"20"],
["0","030915",5,"30"],
["0","030915",6,"40"],
["1","030915",3,"15"],
["1","030915",4,"7" ],
["1","030915",5,"49"],
["1","030915",6,"2" ]]
0600 30in the example just wrong (1200 is 30), or are you trying to do cumulative readings (so adding the current 20 to the previous 10)? \$\endgroup\$