[Jprogramming] transform table columns to rows

Linda A Alvord lindaalvord at verizon.net
Fri Mar 18 05:57:16 UTC 2016


f=: 13 :'18 2$,( ,.{."1 }."2 y),"1 0 }."1 }."2 y'

Linda
-----Original Message-----
From: Programming [mailto:programming-bounces at forums.jsoftware.com] On Behalf Of Joe Bogner
Sent: Thursday, March 17, 2016 10:45 PM
To: programming at jsoftware.com
Subject: [Jprogramming] transform table columns to rows

Is there a simple or efficient transform of

tbl =: ' ' cut every LF cut (0 : 0)
id col1 col2 col3 col4 col5 col6
1 ab cd ef gh hi jk
2 lm no pq rs tu vw
3 xy zz aa bb cc dd
)

+--+----+----+----+----+----+----+

|id|col1|col2|col3|col4|col5|col6|

+--+----+----+----+----+----+----+

|1 |ab |cd |ef |gh |hi |jk |

+--+----+----+----+----+----+----+

|2 |lm |no |pq |rs |tu |vw |

+--+----+----+----+----+----+----+

|3 |xy |zz |aa |bb |cc |dd |

+--+----+----+----+----+----+----+



to


('1';'ab'),('1';'cd'),('1';'ef'),('1';'gh'),('1';'hi'),('1';'jk'),:('2';'lm')

+-+--+

|1|ab|

+-+--+

|1|cd|

+-+--+

|1|ef|

+-+--+

|1|gh|

+-+--+

|1|hi|

+-+--+

|1|jk|

+-+--+

|2|lm|

+-+--+

   ...



In other words, take the first column and duplicate the other columns as rows


thanks in advance
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm



More information about the Programming mailing list