<?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: Struggling with extracting the second largest values for each column in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Struggling-with-extracting-the-second-largest-values-for-each/m-p/61104#M33204</link>
    <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/6657"&gt;@ih&lt;/a&gt;&amp;nbsp;I am sorry, but I need the values from every column and not an entire table.&lt;/P&gt;</description>
    <pubDate>Mon, 25 Jun 2018 19:20:09 GMT</pubDate>
    <dc:creator>amy</dc:creator>
    <dc:date>2018-06-25T19:20:09Z</dc:date>
    <item>
      <title>Struggling with extracting the second largest values for each column</title>
      <link>https://community.jmp.com/t5/Discussions/Struggling-with-extracting-the-second-largest-values-for-each/m-p/60700#M33050</link>
      <description>&lt;P&gt;I have been trying to extract second largest numbers from JMP tables. So far, I have only been manually doing it using&lt;/P&gt;&lt;P&gt;Sort descending( Eval List( {:X1, :X2, :X3}));&lt;/P&gt;&lt;P&gt;How can I just pass the entire table rather than individual column names?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 999px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/11166i0E63ABDB5B2616CD/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jun 2018 19:21:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Struggling-with-extracting-the-second-largest-values-for-each/m-p/60700#M33050</guid>
      <dc:creator>amy</dc:creator>
      <dc:date>2018-06-20T19:21:36Z</dc:date>
    </item>
    <item>
      <title>Re: Struggling with extracting the second largest values for each column</title>
      <link>https://community.jmp.com/t5/Discussions/Struggling-with-extracting-the-second-largest-values-for-each/m-p/60706#M33054</link>
      <description>&lt;P&gt;Here is a little script that I wrote that determines the second highest value across all continuous columns in a data table&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;names default to here(1);
dt=open("$SAMPLE_DATA/semiconductor capability.jmp");

colNamesList= dt&amp;lt;&amp;lt;get column names(string,continuous,numeric);
colSecondMaxValues = {};

// Loop across all continuous columns and find the Max value in
// a column, delete that value, and then find the second max value
// finally, replace the old values, and save the results
For(i=1,i&amp;lt;=nitems(colNamesList),i++,
	colMax=col max(column(dt,colNamesList[i]));
	maxRows = dt&amp;lt;&amp;lt;get rows where(as column(dt,colNamesList[i])==colMax);
	column(dt,colNamesList[i])[maxRows]=.;
	insert into(colSecondMaxValues, col max(column(dt,colNamesList[i])));
	column(dt,colNamesList[i])[maxRows]=colMax;
	);
	
nw = New Window( "Second Max Values",
	Outline Box( "Table of Second Max Values",
		Table Box(
			String Col Box( "Column", colNamesList ),
			Number Col Box( "Second Max Value", colSecondMaxValues )
		)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Jun 2018 20:32:44 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Struggling-with-extracting-the-second-largest-values-for-each/m-p/60706#M33054</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2018-06-20T20:32:44Z</dc:date>
    </item>
    <item>
      <title>Re: Struggling with extracting the second largest values for each column</title>
      <link>https://community.jmp.com/t5/Discussions/Struggling-with-extracting-the-second-largest-values-for-each/m-p/60715#M33060</link>
      <description>&lt;P&gt;If you want the second largest value in the whole table, reguardless of which column it is in:&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/semiconductor capability.jmp" );

//Find the two largest values in the entire table
Sort Descending(Shape(dt &amp;lt;&amp;lt; Get all columns as matrix(),1))[{1, 2}];

//Or, to exclude character columns
Sort Descending(Shape(dt &amp;lt;&amp;lt; Get as matrix(dt &amp;lt;&amp;lt; get column names(numeric)),1))[{1, 2}];&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Jun 2018 03:19:59 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Struggling-with-extracting-the-second-largest-values-for-each/m-p/60715#M33060</guid>
      <dc:creator>ih</dc:creator>
      <dc:date>2018-06-21T03:19:59Z</dc:date>
    </item>
    <item>
      <title>Re: Struggling with extracting the second largest values for each column</title>
      <link>https://community.jmp.com/t5/Discussions/Struggling-with-extracting-the-second-largest-values-for-each/m-p/61103#M33203</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2687"&gt;@txnelson&lt;/a&gt;&amp;nbsp;Thank you for the script. I am trying to make a greater than 300 or 250 condition work for this script and I am unable to understand why it still takes values like 193. Also, how can I find the row number of the second highest value i.e colSecondMaxValues? &amp;nbsp;Thank you very much for your help.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt=open("$SAMPLE_DATA/semiconductor capability.jmp");

colNamesList= dt&amp;lt;&amp;lt;get column names(string,continuous,numeric);
colSecondMaxValues = {};

// Loop across all continuous columns and find the Max value in
// a column, delete that value, and then find the second max value
// finally, replace the old values, and save the results
For(i=1,i&amp;lt;=nitems(colNamesList),i++,
	colMax=col max(column(dt,colNamesList[i]));
	If((abs(colMax)) &amp;gt; 300 | (abs(colMax)) &amp;gt; 250,
	maxRows = dt&amp;lt;&amp;lt;get rows where(as column(dt,colNamesList[i])==colMax);
	show(maxRows);
	column(dt,colNamesList[i])[maxRows]=.;
	insert into(colSecondMaxValues, col max(column(dt,colNamesList[i])));
	show(colSecondMaxValues);
	column(dt,colNamesList[i])[maxRows]=colMax;
	)
	);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Jun 2018 19:18:22 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Struggling-with-extracting-the-second-largest-values-for-each/m-p/61103#M33203</guid>
      <dc:creator>amy</dc:creator>
      <dc:date>2018-06-25T19:18:22Z</dc:date>
    </item>
    <item>
      <title>Re: Struggling with extracting the second largest values for each column</title>
      <link>https://community.jmp.com/t5/Discussions/Struggling-with-extracting-the-second-largest-values-for-each/m-p/61104#M33204</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/6657"&gt;@ih&lt;/a&gt;&amp;nbsp;I am sorry, but I need the values from every column and not an entire table.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jun 2018 19:20:09 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Struggling-with-extracting-the-second-largest-values-for-each/m-p/61104#M33204</guid>
      <dc:creator>amy</dc:creator>
      <dc:date>2018-06-25T19:20:09Z</dc:date>
    </item>
    <item>
      <title>Re: Struggling with extracting the second largest values for each column</title>
      <link>https://community.jmp.com/t5/Discussions/Struggling-with-extracting-the-second-largest-values-for-each/m-p/61106#M33206</link>
      <description>&lt;P&gt;Your comparison component in your IF() function has a logic issue.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( (Abs( colMax )) &amp;gt; 300 | (Abs( colMax )) &amp;gt; 250&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;any value that is &amp;gt; 250 will make the comparison true, therefore, the &amp;gt;300 is not needed.&lt;/P&gt;
&lt;P&gt;The comparison only needs to be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( ( Abs( colMax ) &amp;gt; 250,&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You ask why you are getting values of 193?&amp;nbsp; That is because the values being printed out are the second highest value for the column, and your filtering is based upon the maximum value in the column.&amp;nbsp; The second highest value can be of any value.&amp;nbsp; If you had the following values in a column&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;82&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;15&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;600&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;44&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;193&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;The maximum column value is 600, so it would pass your IF() clause of Max Col() &amp;gt; 250, and the second highest value in the colum is 193&lt;/P&gt;
&lt;P&gt;Concerning your question about "&lt;SPAN&gt;how can I find the row number of the second highest value i.e colSecondMaxValues?", the way to do this is already in the script.&amp;nbsp; The statement&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;maxRows = dt &amp;lt;&amp;lt; get rows where( As Column( dt, colNamesList[i] ) == colMax );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;returns a matrix of the row numbers for the rows that have the Maximum values in the column.&amp;nbsp; If you want the row numbers for the second highest value, you just need to get the rows where they equal the second max value.&amp;nbsp; So if you add&amp;nbsp;this statement after the Insert Into() function, you will get the row(s) that have the second highest value&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Show(
			dt &amp;lt;&amp;lt; get rows where(
				As Column( dt, colNamesList[i] ) == Col Max( Column( dt, colNamesList[i] ) )
			)
		);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Here is the complete code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Open( "$SAMPLE_DATA/semiconductor capability.jmp" );

colNamesList = dt &amp;lt;&amp;lt; get column names( string, continuous, numeric );
colSecondMaxValues = {};

// Loop across all continuous columns and find the Max value in
// a column, delete that value, and then find the second max value
// finally, replace the old values, and save the results
For( i = 1, i &amp;lt;= N Items( colNamesList ), i++,
	colMax = Col Max( Column( dt, colNamesList[i] ) );
	If( Abs( colMax ) &amp;gt; 250,
		maxRows = dt &amp;lt;&amp;lt; get rows where( As Column( dt, colNamesList[i] ) == colMax );
		Show( maxRows );
		Column( dt, colNamesList[i] )[maxRows] = .;
		Insert Into( colSecondMaxValues, Col Max( Column( dt, colNamesList[i] ) ) );
		Show(
			dt &amp;lt;&amp;lt; get rows where(
				As Column( dt, colNamesList[i] ) == Col Max( Column( dt, colNamesList[i] ) )
			)
		);
		Show( colSecondMaxValues );
		Column( dt, colNamesList[i] )[maxRows] = colMax;
	);
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Jun 2018 20:12:54 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Struggling-with-extracting-the-second-largest-values-for-each/m-p/61106#M33206</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2018-06-25T20:12:54Z</dc:date>
    </item>
  </channel>
</rss>

