-----Original Message-----
From: Linda A Alvord [mailto:[email protected]] 
Sent: Saturday, March 19, 2016 12:47 PM
To: '[email protected]'
Subject: RE: [Jprogramming] transform table columns to rows

Joe, your problem, like many others, forces us to simplify, simplify, simplify.

Here's a 4th grade, simple J version of the tacit solution Henry provided.

h=: 13 :'([:,/({. ,. }.)"1)}.y'

It took me a while to get it right, but it is certainly better than my first 
version.

Linda

-----Original
-----Original Message-----
From: Programming [mailto:[email protected]] On Behalf 
Of Joe Bogner
Sent: Friday, March 18, 2016 1:39 PM
To: [email protected]
Subject: Re: [Jprogramming] transform table columns to rows

Solutions like this remind me how grateful I am to have J in my toolbox.

I have a 6,000 row excel file with 75 columns that I needed to 'unpivot'

I could have used the Excel Power Query's Unpivot function, but without that or 
J it would have been a hassle.

On Thu, Mar 17, 2016 at 10:54 PM, Henry Rich <[email protected] Joe, your 
problem, like many others, forces us to simplify, simplify, simplify.

Here's a 4th grade, simple J version of the tacit solution Henry provided.

h=: 13 :'([:,/({. ,. }.)"1)}.y'

It took me a while to get it right, but it is certainly better than my first 
version.

Linda

-----Original om> wrote:

> Your table is regular, so
>
> ,/@:(({. ,. }.)"1)
>
> would also work.
>
> Henry Rich
>
>
> On 3/17/2016 10:47 PM, Henry Rich wrote:
>
>> ;@:(<@({. ,. }.)"1)
>>
>> Untested.
>>
>> Henry Rich
>>
>> On 3/17/2016 10:44 PM, Joe Bogner wrote:
>>
>>> 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
>>>
>>
>> ---------------------------------------------------------------------
>> -
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

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

Reply via email to