<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: transpose list of lists (summarize()) without a for loop in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/transpose-list-of-lists-summarize-without-a-for-loop/m-p/76499#M36109</link>
    <description>&lt;P&gt;DOH!&amp;nbsp; I suppose you could write the results to a table, transpose that, and create lists from the table. Might still have a for loop in there though.&amp;nbsp; Hmmmm...&lt;/P&gt;</description>
    <pubDate>Fri, 28 Sep 2018 18:59:25 GMT</pubDate>
    <dc:creator>pmroz</dc:creator>
    <dc:date>2018-09-28T18:59:25Z</dc:date>
    <item>
      <title>transpose list of lists (summarize()) without a for loop</title>
      <link>https://community.jmp.com/t5/Discussions/transpose-list-of-lists-summarize-without-a-for-loop/m-p/76462#M36104</link>
      <description>&lt;P&gt;Can anyone think of a way to transpose a list of lists like what comes from the following script so that each row is grouped together instead of by column.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know I can do it with a for loop but I'm wondering if there's anything better or less brute.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names default to here(1);
dt = open("$SAMPLE_DATA\Big Class.jmp");
summarize(dt, d = By(:age, :sex));

rows = nitems(d);
cols = nitems(d[1]);

show(rows, cols);

// rows = 2;
// cols = 12;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For this I want to change it from 2 lists of 12 to 12 lists of 2.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Adding a few people that I think might either like this challenge or already have something.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/4550"&gt;@pmroz&lt;/a&gt;,&amp;nbsp;&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/1855"&gt;@Justin_Chilton&lt;/a&gt;,&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/70"&gt;@gzmorgan0&lt;/a&gt;,&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/4553"&gt;@msharp&lt;/a&gt;,&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/182"&gt;@ms&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2018 18:16:52 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/transpose-list-of-lists-summarize-without-a-for-loop/m-p/76462#M36104</guid>
      <dc:creator>vince_faller</dc:creator>
      <dc:date>2018-09-28T18:16:52Z</dc:date>
    </item>
    <item>
      <title>Re: transpose list of lists (summarize()) without a for loop</title>
      <link>https://community.jmp.com/t5/Discussions/transpose-list-of-lists-summarize-without-a-for-loop/m-p/76481#M36107</link>
      <description>&lt;P&gt;It's not a gold watch but it works.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names default to here(1);
dt = open("$SAMPLE_DATA\Big Class.jmp");
summarize(dt, d = By(:age, :sex));

nrows = nitems(d);
ncols = nitems(d[1]);

show(nrows, ncols);

// nrows = 2;
// ncols = 12;

trans_list = {};

for (i = 1, i &amp;lt;= ncols, i++,
	one_list = {};
	for (k = 1, k &amp;lt;= nrows, k++,
		one_list[k] = d[k][i];
	);
	trans_list[i] = one_list;
);
show(trans_list);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;trans_list = {{"12", "F"}, {"12", "M"}, {"13", "F"}, {"13", "M"}, {"14", "F"}, {"14", "M"}, {"15", "F"}, {"15", "M"}, {"16", "F"}, {"16", "M"}, {"17", "F"}, {"17", "M"}};&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Sep 2018 18:35:04 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/transpose-list-of-lists-summarize-without-a-for-loop/m-p/76481#M36107</guid>
      <dc:creator>pmroz</dc:creator>
      <dc:date>2018-09-28T18:35:04Z</dc:date>
    </item>
    <item>
      <title>Re: transpose list of lists (summarize()) without a for loop</title>
      <link>https://community.jmp.com/t5/Discussions/transpose-list-of-lists-summarize-without-a-for-loop/m-p/76498#M36108</link>
      <description>&lt;P&gt;I feel like you didn't read the without a for loop part. :p&lt;/img&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2018 18:40:57 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/transpose-list-of-lists-summarize-without-a-for-loop/m-p/76498#M36108</guid>
      <dc:creator>vince_faller</dc:creator>
      <dc:date>2018-09-28T18:40:57Z</dc:date>
    </item>
    <item>
      <title>Re: transpose list of lists (summarize()) without a for loop</title>
      <link>https://community.jmp.com/t5/Discussions/transpose-list-of-lists-summarize-without-a-for-loop/m-p/76499#M36109</link>
      <description>&lt;P&gt;DOH!&amp;nbsp; I suppose you could write the results to a table, transpose that, and create lists from the table. Might still have a for loop in there though.&amp;nbsp; Hmmmm...&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2018 18:59:25 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/transpose-list-of-lists-summarize-without-a-for-loop/m-p/76499#M36109</guid>
      <dc:creator>pmroz</dc:creator>
      <dc:date>2018-09-28T18:59:25Z</dc:date>
    </item>
    <item>
      <title>Re: transpose list of lists (summarize()) without a for loop</title>
      <link>https://community.jmp.com/t5/Discussions/transpose-list-of-lists-summarize-without-a-for-loop/m-p/76628#M36110</link>
      <description>&lt;P&gt;PMROZ's nested for loops is probably the best.&amp;nbsp; If you are looking for alternatives, I can think of two additional ways.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your data is all numeric you could use matrices which would be pretty slick.&amp;nbsp; This doesn't have for loops however, the list of lists returned from summarize returns all character values, even for numeric columns.&amp;nbsp; Which means you would need a nested for loop to convert everything to numbers (if all your data is columns) so that won't be helpful for your problem.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The second option is to convert the list of lists to a data table, transpose that, then turn back.&amp;nbsp; This requires two for loops for the conversions (I'm not aware of any slick way to convert between nested lists and data tables).&amp;nbsp;&amp;nbsp;This is probably slower than PMROZ's solution since you have the overhead of creating a data table, however, it's possibly faster for larger datasets.&amp;nbsp; If you don't actually convert back to a list of lists and just use the transposed data table instead, you could save some time as well.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names default to here(1);
dt = open("$SAMPLE_DATA\Big Class.jmp");
summarize(dt, d = By(:age, :sex));
rows = nitems(d);
cols = nitems(d[1]);
show(rows, cols);


//Turn List of Lists into DT ()
dtLL = New Table("Lists of Lists");
for(i=1,i&amp;lt;=nitems(d),i++,
	dtLL &amp;lt;&amp;lt; New Column(char(i), Character, Nominal, Values(d[i]));
);
//Transpose DT
cols = dtLL &amp;lt;&amp;lt; Get Column Names;
dtT = dtLL &amp;lt;&amp;lt; Transpose(columns(cols));
//Turn back into list of lists
trans_list = {};
for(i=2,i&amp;lt;=ncols(dtT),i++,
	trans_list[i] = column(dtT,i) &amp;lt;&amp;lt;Get Values;
);
print(trans_list);


//Matrix if all numbers
summarize(dt, d2 = By(:age, :height));
//d2 is all characters...
m = Matrix(d2);
//Example with list of lists of numbers
d2 = {};
d2[1] = As List(dt:height &amp;lt;&amp;lt; Get Values);
d2[2] = As List(dt:height &amp;lt;&amp;lt; Get Values);
m = Matrix(d2);
mT = Transpose(m);
d2T = As List(mT);
print(d2T);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Sep 2018 19:50:59 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/transpose-list-of-lists-summarize-without-a-for-loop/m-p/76628#M36110</guid>
      <dc:creator>msharp</dc:creator>
      <dc:date>2018-09-28T19:50:59Z</dc:date>
    </item>
    <item>
      <title>Re: transpose list of lists (summarize()) without a for loop</title>
      <link>https://community.jmp.com/t5/Discussions/transpose-list-of-lists-summarize-without-a-for-loop/m-p/76645#M36111</link>
      <description>&lt;P&gt;I found this way but it's slower.&amp;nbsp; :(&lt;/img&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names default to here(1);
dt = open("$SAMPLE_DATA\Big Class.jmp")
summarize(dt, list = By(:age, :sex));

rows = nitems(list[1]);
cols = nitems(list);
list_flat = parse("{"||substitute(char(list), "}", "", "{", "")||"}");
insert into(list_flat, repeat({"@@@"}, rows));
list_sort = list_flat[	shape(1::rows*(cols+1), cols+1)` ];
remove from(list_sort, -1);
t_list = parse("{"|| 
	substitute(char(list_sort), 
		", \!"@@@\!",", "},{"
	) 
||"}");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2018 21:42:48 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/transpose-list-of-lists-summarize-without-a-for-loop/m-p/76645#M36111</guid>
      <dc:creator>vince_faller</dc:creator>
      <dc:date>2018-09-28T21:42:48Z</dc:date>
    </item>
    <item>
      <title>Re: transpose list of lists (summarize()) without a for loop</title>
      <link>https://community.jmp.com/t5/Discussions/transpose-list-of-lists-summarize-without-a-for-loop/m-p/76647#M36112</link>
      <description>&lt;P&gt;Here's an idea based on&amp;nbsp;Repeat(). A&amp;nbsp;function that&amp;nbsp;essentially is a loop but returns the list directly, without the need to loop any&amp;nbsp;assignments.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In earlier versions of JMP I experienced&amp;nbsp;that Repeat() was way faster than For() in&amp;nbsp;building lists but I think that was "fixed" in JMP 13.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
dt = Open("$SAMPLE_DATA\Big Class.jmp");
Summarize(dt, d = By(:age, :sex));

transposed_d = Local({i = 0}, Repeat({i++ ; Eval List({d[1][i], d[2][i]})}, N Items(d[1])));
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2018 22:03:30 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/transpose-list-of-lists-summarize-without-a-for-loop/m-p/76647#M36112</guid>
      <dc:creator>ms</dc:creator>
      <dc:date>2018-09-28T22:03:30Z</dc:date>
    </item>
    <item>
      <title>Re: transpose list of lists (summarize()) without a for loop</title>
      <link>https://community.jmp.com/t5/Discussions/transpose-list-of-lists-summarize-without-a-for-loop/m-p/76648#M36113</link>
      <description>&lt;P&gt;Using the new Python hooks in JMP 14 I thought I could cheat.&amp;nbsp; It mostly works.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
dt = Open("$SAMPLE_DATA\Big Class.jmp");
Summarize(dt, d = By(:age, :sex));

Python Init();
ml = Python Execute(
	{d},
	{x, d},
	"\[
import numpy as np
x = np.transpose(d) # matrix product
print('x=', x)
]\"
);
Show( x, d );
Python Term();&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Sep 2018 22:31:12 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/transpose-list-of-lists-summarize-without-a-for-loop/m-p/76648#M36113</guid>
      <dc:creator>msharp</dc:creator>
      <dc:date>2018-09-28T22:31:12Z</dc:date>
    </item>
    <item>
      <title>Re: transpose list of lists (summarize()) without a for loop</title>
      <link>https://community.jmp.com/t5/Discussions/transpose-list-of-lists-summarize-without-a-for-loop/m-p/76778#M36118</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names default to here(1);
dt = open("$SAMPLE_DATA\Big Class.jmp");

//Since column formulas are by row, it uses a built in For Loop this maintains the table values but requires a table....&lt;BR /&gt;//This is not a solution for two generic lists&lt;BR /&gt;
dt &amp;lt;&amp;lt; New Column( "Age,Sex",
		Expression,
		"None",
		Formula( Eval List( {:age[Empty()], :sex[Empty()]} ) ),
		Suppress Eval
	);

myList=  (Associative Array(Column("Age,Sex")) &amp;lt;&amp;lt;get keys);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 29 Sep 2018 09:17:04 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/transpose-list-of-lists-summarize-without-a-for-loop/m-p/76778#M36118</guid>
      <dc:creator>gzmorgan0</dc:creator>
      <dc:date>2018-09-29T09:17:04Z</dc:date>
    </item>
    <item>
      <title>Re: transpose list of lists (summarize()) without a for loop</title>
      <link>https://community.jmp.com/t5/Discussions/transpose-list-of-lists-summarize-without-a-for-loop/m-p/76871#M36124</link>
      <description>&lt;P&gt;MS, repeat soution is very nice!!&lt;/P&gt;</description>
      <pubDate>Sat, 29 Sep 2018 09:13:49 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/transpose-list-of-lists-summarize-without-a-for-loop/m-p/76871#M36124</guid>
      <dc:creator>gzmorgan0</dc:creator>
      <dc:date>2018-09-29T09:13:49Z</dc:date>
    </item>
    <item>
      <title>Re: transpose list of lists (summarize()) without a for loop</title>
      <link>https://community.jmp.com/t5/Discussions/transpose-list-of-lists-summarize-without-a-for-loop/m-p/77315#M36141</link>
      <description>&lt;P&gt;Repeat: MS your repeat solution is very nice. :)&lt;/img&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Oct 2018 17:48:05 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/transpose-list-of-lists-summarize-without-a-for-loop/m-p/77315#M36141</guid>
      <dc:creator>pmroz</dc:creator>
      <dc:date>2018-10-01T17:48:05Z</dc:date>
    </item>
    <item>
      <title>Re: transpose list of lists (summarize()) without a for loop</title>
      <link>https://community.jmp.com/t5/Discussions/transpose-list-of-lists-summarize-without-a-for-loop/m-p/348987#M59981</link>
      <description>&lt;P&gt;I had the exact same question&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2610"&gt;@vince_faller&lt;/a&gt;&amp;nbsp;. &amp;nbsp;Thanks for asking. &amp;nbsp;I've posted a request for a feature like this to be added to the next version of JMP. &amp;nbsp;Let's see...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.jmp.com/t5/JMP-Wish-List/Transpose-List-of-Lists-without-a-for-loop/idi-p/348968" target="_blank"&gt;https://community.jmp.com/t5/JMP-Wish-List/Transpose-List-of-Lists-without-a-for-loop/idi-p/348968&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jan 2021 02:19:33 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/transpose-list-of-lists-summarize-without-a-for-loop/m-p/348987#M59981</guid>
      <dc:creator>nikles</dc:creator>
      <dc:date>2021-01-15T02:19:33Z</dc:date>
    </item>
  </channel>
</rss>

