<?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: Create a associative array from unique selected rows and row number in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Create-a-associative-array-from-unique-selected-rows-and-row/m-p/258831#M50826</link>
    <description>&lt;P&gt;To get the subset tables that I believe you want, modify the last part of Ian's code so it appears as below. Specifically, nest the (new) j-indexed for-loop within Ian's i-indexed for loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;Brady&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// Build associative arrays from current key list
subject_aa = associative array();
for (i = 1, i &amp;lt;= nitems(key_list), i++,
	found_rows = dt &amp;lt;&amp;lt; get rows where(as column(dt, "Subject") == key_list[i]);
	subject_aa[key_list[i]] = found_rows;
	for(j = 1, j&amp;lt;=nitems(found_rows)-1, j++,
		dt &amp;lt;&amp;lt; subset(rows(found_Rows[j] :: found_Rows[j+1]));
	)
);
show(subject_aa);

&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 18 Apr 2020 00:34:56 GMT</pubDate>
    <dc:creator>brady_brady</dc:creator>
    <dc:date>2020-04-18T00:34:56Z</dc:date>
    <item>
      <title>Create a associative array from unique selected rows and row number</title>
      <link>https://community.jmp.com/t5/Discussions/Create-a-associative-array-from-unique-selected-rows-and-row/m-p/257860#M50669</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have table in which I have selected rows where subject is science or Math (using select where function). Now I want to create associative array which stores the row number of all selected with unique entries of a particular column.&lt;/P&gt;&lt;P&gt;After that I want to start a loop for all keys of the associative array. Which will subset the rows from key[i] to Key[i+1] for each value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;For Example:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Row_Number&lt;/TD&gt;&lt;TD&gt;Student&lt;/TD&gt;&lt;TD&gt;Sequence&lt;/TD&gt;&lt;TD&gt;Subject&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Economics&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;A&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;Science&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;Physics&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;4&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;A&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;5&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;Math&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;5&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;A&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;Science&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;Chemistry&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;7&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;A&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;6&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;Science&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;8&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;A&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;Math&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Social&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*Rows in blue color, I have selected using select where function.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I want to create variables which store Associative Array :&amp;nbsp;["Science" =&amp;gt; {2,5,7}], "Math" =&amp;gt; {4,8}].&lt;/LI&gt;&lt;LI&gt;Then I want to create a loop for both keys which will subset and generate 3 tables.&lt;UL&gt;&lt;LI&gt;Table 1: From row number 2 to 5&lt;/LI&gt;&lt;LI&gt;Table 2: From row number 5 to 7&lt;/LI&gt;&lt;LI&gt;Table 3 : From row number 4 to 8&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Please help, how I can solve.&lt;/P&gt;&lt;P&gt;Thanks :)&lt;/img&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Apr 2020 11:45:33 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-a-associative-array-from-unique-selected-rows-and-row/m-p/257860#M50669</guid>
      <dc:creator>Rajat</dc:creator>
      <dc:date>2020-04-14T11:45:33Z</dc:date>
    </item>
    <item>
      <title>Re: Create a associative array from unique selected rows and row number</title>
      <link>https://community.jmp.com/t5/Discussions/Create-a-associative-array-from-unique-selected-rows-and-row/m-p/257870#M50670</link>
      <description>&lt;P&gt;This code should get you started.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = New Table( "Subjects", Add Rows( 9 ),
	New Column( "Student", Character( 16 ), "Nominal",
		Set Values( {"A", "A", "A", "A", "A", "A", "A", "A", "A"} ) ),
	New Column( "Sequence", Numeric, "Continuous", Format( "Best", 12 ),
		Set Values( [1, 2, 4, 5, 2, 4, 6, 2, 1] ) ),
	New Column( "Subject", Character( 16 ), "Nominal",
		Set Values( {"Economics", "Science", "Physics", "Math", "Science", "Chemistry",
			"Science", "Math", "Social"} ) )
);

key_list = {"Science", "Math"};
subject_aa = associative array();
for (i = 1, i &amp;lt;= nitems(key_list), i++,
	found_rows = dt &amp;lt;&amp;lt; get rows where(as column(dt, "Subject") == key_list[i]);
	subject_aa[key_list[i]] = found_rows;
);
show(subject_aa);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Apr 2020 12:42:14 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-a-associative-array-from-unique-selected-rows-and-row/m-p/257870#M50670</guid>
      <dc:creator>pmroz</dc:creator>
      <dc:date>2020-04-14T12:42:14Z</dc:date>
    </item>
    <item>
      <title>Re: Create a associative array from unique selected rows and row number</title>
      <link>https://community.jmp.com/t5/Discussions/Create-a-associative-array-from-unique-selected-rows-and-row/m-p/257883#M50676</link>
      <description>&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/4550"&gt;@pmroz&lt;/a&gt; Thanks for replying.&lt;BR /&gt;My data set is very big and using this approach might take more time.&lt;BR /&gt;Also, my key_list is not fixed it depends based on condition whether it contains particular text or not.</description>
      <pubDate>Tue, 14 Apr 2020 13:40:45 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-a-associative-array-from-unique-selected-rows-and-row/m-p/257883#M50676</guid>
      <dc:creator>Rajat</dc:creator>
      <dc:date>2020-04-14T13:40:45Z</dc:date>
    </item>
    <item>
      <title>Re: Create a associative array from unique selected rows and row number</title>
      <link>https://community.jmp.com/t5/Discussions/Create-a-associative-array-from-unique-selected-rows-and-row/m-p/258069#M50720</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/4550"&gt;@pmroz&lt;/a&gt;&amp;nbsp;has done most of the work, which one can add to:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;NamesDefaultToHere(1);

dt = New Table( "Subjects",
	Add Rows( 9 ),
	New Column( "Student",
		Character( 16 ),
		"Nominal",
		Set Values( {"A", "A", "A", "A", "A", "A", "A", "A", "A"} )
	),
	New Column( "Sequence",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [1, 2, 4, 5, 2, 4, 6, 2, 1] )
	),
	New Column( "Subject",
		Character( 16 ),
		"Nominal",
		Set Values(
			{"Economics", "Science", "Physics", "Math", "Science", "Chemistry", "Science", "Math", "Social"}
		)
	)
);

// Make any row selection (in this case, the 'blue' rows)
dt &amp;lt;&amp;lt; selectRows({2, 4, 5, 7, 8 });

// Get key list from the current row selection
subjectVals = Column(dt, "Subject")[dt &amp;lt;&amp;lt; getSelectedRows];
key_list = AssociativeArray(subjectVals) &amp;lt;&amp;lt; getKeys;

// Build associative arrays from current key list
subject_aa = associative array();
for (i = 1, i &amp;lt;= nitems(key_list), i++,
	found_rows = dt &amp;lt;&amp;lt; get rows where(as column(dt, "Subject") == key_list[i]);
	subject_aa[key_list[i]] = found_rows;
);
show(subject_aa);

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Right click on the JSL key words in the editor and do 'Help Scripting Index' to get more information.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using your example, once you have the associative arrays the specification of the thee tables you say you want was unclear to me.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Apr 2020 09:56:35 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-a-associative-array-from-unique-selected-rows-and-row/m-p/258069#M50720</guid>
      <dc:creator>ian_jmp</dc:creator>
      <dc:date>2020-04-15T09:56:35Z</dc:date>
    </item>
    <item>
      <title>Re: Create a associative array from unique selected rows and row number</title>
      <link>https://community.jmp.com/t5/Discussions/Create-a-associative-array-from-unique-selected-rows-and-row/m-p/258831#M50826</link>
      <description>&lt;P&gt;To get the subset tables that I believe you want, modify the last part of Ian's code so it appears as below. Specifically, nest the (new) j-indexed for-loop within Ian's i-indexed for loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;Brady&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// Build associative arrays from current key list
subject_aa = associative array();
for (i = 1, i &amp;lt;= nitems(key_list), i++,
	found_rows = dt &amp;lt;&amp;lt; get rows where(as column(dt, "Subject") == key_list[i]);
	subject_aa[key_list[i]] = found_rows;
	for(j = 1, j&amp;lt;=nitems(found_rows)-1, j++,
		dt &amp;lt;&amp;lt; subset(rows(found_Rows[j] :: found_Rows[j+1]));
	)
);
show(subject_aa);

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 18 Apr 2020 00:34:56 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-a-associative-array-from-unique-selected-rows-and-row/m-p/258831#M50826</guid>
      <dc:creator>brady_brady</dc:creator>
      <dc:date>2020-04-18T00:34:56Z</dc:date>
    </item>
  </channel>
</rss>

