<?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: Filter the most frequent value in multiple columns in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Filter-the-most-frequent-value-in-multiple-columns/m-p/682715#M86828</link>
    <description>&lt;P&gt;Here is a script that should give you a leg up in solving your issue&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

// build an example data table
dt = New Table( "Example",
	add rows( 20 ),
	New Column( "A",
		character,
		formula(
			rand = Random Uniform( 0, 100 );
			If(
				rand &amp;gt;= 0 &amp;amp; rand &amp;lt;= 40, x = 1,
				rand &amp;gt;= 40 &amp;amp; rand &amp;lt;= 60, x = 2,
				rand &amp;gt;= 60 &amp;amp; rand &amp;lt;= 80, x = 3,
				x = 4
			);
			"A" || Char( x );
		)
	),
	New Column( "B",
		character,
		formula(
			rand = Random Uniform( 0, 100 );
			If(
				rand &amp;gt;= 0 &amp;amp; rand &amp;lt;= 20, x = 1,
				rand &amp;gt;= 20 &amp;amp; rand &amp;lt;= 60, x = 2,
				rand &amp;gt;= 60 &amp;amp; rand &amp;lt;= 80, x = 3,
				x = 4
			);
			"B" || Char( x );
		)
	),
	New Column( "C",
		character,
		formula(
			rand = Random Uniform( 0, 100 );
			If(
				rand &amp;gt;= 0 &amp;amp; rand &amp;lt;= 20, x = 1,
				rand &amp;gt;= 20 &amp;amp; rand &amp;lt;= 40, x = 2,
				rand &amp;gt;= 40 &amp;amp; rand &amp;lt;= 80, x = 3,
				x = 4
			);
			"C" || Char( x );
		)
	),
	New Column( "D",
		character,
		formula(
			rand = Random Uniform( 0, 100 );
			If(
				rand &amp;gt;= 0 &amp;amp; rand &amp;lt;= 20, x = 1,
				rand &amp;gt;= 20 &amp;amp; rand &amp;lt;= 40, x = 2,
				rand &amp;gt;= 40 &amp;amp; rand &amp;lt;= 60, x = 3,
				x = 4
			);
			"D" || Char( x );
		)
	)
);


// The JSL below is the code that does the actual work
Data Table( "Example" ) &amp;lt;&amp;lt; Stack(
	columns( :A, :B, :C, :D&lt;/img&gt; ),
	Source Label Column( "Column" ),
	Stacked Data Column( "Data" ),
	Output Table( "Stacked" )
);

dtS = Data Table( "Stacked" ) &amp;lt;&amp;lt; Summary(
	Group( :Column, :Data ),
	Freq( "None" ),
	Weight( "None" ),
	output table name( "Summary" )
);

dtS &amp;lt;&amp;lt; select where( :N Rows[Row()] == col max(:N Rows, :Data));
dtS &amp;lt;&amp;lt; new column("Mode", formula(
	Col Max(:N Rows, :Column)
));
dtS &amp;lt;&amp;lt; select where( :N Rows == :Mode);
dtS &amp;lt;&amp;lt; invert row selection &amp;lt;&amp;lt; delete rows;

eval(parse(
"dt &amp;lt;&amp;lt; Select Where (dt:\!"" || dts:column[1]  || "\!"n == dtS:Data[1] );"));

For( i=2,i&amp;lt;=NRows(dtS), i++,
	eval(parse(
	"dt &amp;lt;&amp;lt; Select Where (dt:\!"" || dts:column[i]  || "\!"n == dtS:Data[i] , current selection(\!"extend\!"));"));
);

dtFinal = dt &amp;lt;&amp;lt; Subset( selected columns(0), selected rows(1), output table("Final"));
	


&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 30 Sep 2023 06:47:38 GMT</pubDate>
    <dc:creator>txnelson</dc:creator>
    <dc:date>2023-09-30T06:47:38Z</dc:date>
    <item>
      <title>Filter the most frequent value in multiple columns</title>
      <link>https://community.jmp.com/t5/Discussions/Filter-the-most-frequent-value-in-multiple-columns/m-p/682688#M86823</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My goal is to select only the rows that have the most common values (character type) in each column.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For instance, my table has four columns: A, B, C, and D. The values that appear the most in columns A, B, C, and D are A1, B2, C3, and D4, respectively. How can I write a JSL code that filters the rows by these values and creates a new table with the filtered data? Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sat, 30 Sep 2023 00:31:22 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Filter-the-most-frequent-value-in-multiple-columns/m-p/682688#M86823</guid>
      <dc:creator>Dzungtran</dc:creator>
      <dc:date>2023-09-30T00:31:22Z</dc:date>
    </item>
    <item>
      <title>Re: Filter the most frequent value in multiple columns</title>
      <link>https://community.jmp.com/t5/Discussions/Filter-the-most-frequent-value-in-multiple-columns/m-p/682702#M86826</link>
      <description>&lt;P&gt;If you had data like this where (COL -&amp;gt; Most appearances) is A -&amp;gt; A1, B -&amp;gt; B2, C -&amp;gt; C1 (in reality C has a tie, how should these be handled?)&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1696053459763.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/57127i10E903C1F35F18EE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_0-1696053459763.png" alt="jthi_0-1696053459763.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Would you wish to only keep row1 as it has A1, B2 and C1? And if there were more rows with the same values, would you want to keep them all? Or are you looking for something totally different, for example do you want to have a table which just has the values which appear the most?&lt;/P&gt;</description>
      <pubDate>Sat, 30 Sep 2023 06:00:16 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Filter-the-most-frequent-value-in-multiple-columns/m-p/682702#M86826</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-09-30T06:00:16Z</dc:date>
    </item>
    <item>
      <title>Re: Filter the most frequent value in multiple columns</title>
      <link>https://community.jmp.com/t5/Discussions/Filter-the-most-frequent-value-in-multiple-columns/m-p/682715#M86828</link>
      <description>&lt;P&gt;Here is a script that should give you a leg up in solving your issue&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

// build an example data table
dt = New Table( "Example",
	add rows( 20 ),
	New Column( "A",
		character,
		formula(
			rand = Random Uniform( 0, 100 );
			If(
				rand &amp;gt;= 0 &amp;amp; rand &amp;lt;= 40, x = 1,
				rand &amp;gt;= 40 &amp;amp; rand &amp;lt;= 60, x = 2,
				rand &amp;gt;= 60 &amp;amp; rand &amp;lt;= 80, x = 3,
				x = 4
			);
			"A" || Char( x );
		)
	),
	New Column( "B",
		character,
		formula(
			rand = Random Uniform( 0, 100 );
			If(
				rand &amp;gt;= 0 &amp;amp; rand &amp;lt;= 20, x = 1,
				rand &amp;gt;= 20 &amp;amp; rand &amp;lt;= 60, x = 2,
				rand &amp;gt;= 60 &amp;amp; rand &amp;lt;= 80, x = 3,
				x = 4
			);
			"B" || Char( x );
		)
	),
	New Column( "C",
		character,
		formula(
			rand = Random Uniform( 0, 100 );
			If(
				rand &amp;gt;= 0 &amp;amp; rand &amp;lt;= 20, x = 1,
				rand &amp;gt;= 20 &amp;amp; rand &amp;lt;= 40, x = 2,
				rand &amp;gt;= 40 &amp;amp; rand &amp;lt;= 80, x = 3,
				x = 4
			);
			"C" || Char( x );
		)
	),
	New Column( "D",
		character,
		formula(
			rand = Random Uniform( 0, 100 );
			If(
				rand &amp;gt;= 0 &amp;amp; rand &amp;lt;= 20, x = 1,
				rand &amp;gt;= 20 &amp;amp; rand &amp;lt;= 40, x = 2,
				rand &amp;gt;= 40 &amp;amp; rand &amp;lt;= 60, x = 3,
				x = 4
			);
			"D" || Char( x );
		)
	)
);


// The JSL below is the code that does the actual work
Data Table( "Example" ) &amp;lt;&amp;lt; Stack(
	columns( :A, :B, :C, :D&lt;/img&gt; ),
	Source Label Column( "Column" ),
	Stacked Data Column( "Data" ),
	Output Table( "Stacked" )
);

dtS = Data Table( "Stacked" ) &amp;lt;&amp;lt; Summary(
	Group( :Column, :Data ),
	Freq( "None" ),
	Weight( "None" ),
	output table name( "Summary" )
);

dtS &amp;lt;&amp;lt; select where( :N Rows[Row()] == col max(:N Rows, :Data));
dtS &amp;lt;&amp;lt; new column("Mode", formula(
	Col Max(:N Rows, :Column)
));
dtS &amp;lt;&amp;lt; select where( :N Rows == :Mode);
dtS &amp;lt;&amp;lt; invert row selection &amp;lt;&amp;lt; delete rows;

eval(parse(
"dt &amp;lt;&amp;lt; Select Where (dt:\!"" || dts:column[1]  || "\!"n == dtS:Data[1] );"));

For( i=2,i&amp;lt;=NRows(dtS), i++,
	eval(parse(
	"dt &amp;lt;&amp;lt; Select Where (dt:\!"" || dts:column[i]  || "\!"n == dtS:Data[i] , current selection(\!"extend\!"));"));
);

dtFinal = dt &amp;lt;&amp;lt; Subset( selected columns(0), selected rows(1), output table("Final"));
	


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 30 Sep 2023 06:47:38 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Filter-the-most-frequent-value-in-multiple-columns/m-p/682715#M86828</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2023-09-30T06:47:38Z</dc:date>
    </item>
  </channel>
</rss>

