<?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 Identify Same-Name Items in a List in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Identify-Same-Name-Items-in-a-List/m-p/754103#M93619</link>
    <description>&lt;P&gt;I'm wondering if there's a slick way to identify items in a list that are duplicates of each other.&amp;nbsp; My list looks like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;values = {"ABC", "DEF", "Per", "Per", "Per", "Per", "Per", "XYZ", "UVW"};&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I want to return all of the positions of "Per" in the list.&amp;nbsp; I.e.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;[3, 4, 5, 6, 7]&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I can loop over the list to get the answer.&amp;nbsp; But is there another way that avoids the loop?&lt;/P&gt;</description>
    <pubDate>Tue, 14 May 2024 01:35:03 GMT</pubDate>
    <dc:creator>pmroz</dc:creator>
    <dc:date>2024-05-14T01:35:03Z</dc:date>
    <item>
      <title>Identify Same-Name Items in a List</title>
      <link>https://community.jmp.com/t5/Discussions/Identify-Same-Name-Items-in-a-List/m-p/754103#M93619</link>
      <description>&lt;P&gt;I'm wondering if there's a slick way to identify items in a list that are duplicates of each other.&amp;nbsp; My list looks like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;values = {"ABC", "DEF", "Per", "Per", "Per", "Per", "Per", "XYZ", "UVW"};&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I want to return all of the positions of "Per" in the list.&amp;nbsp; I.e.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;[3, 4, 5, 6, 7]&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I can loop over the list to get the answer.&amp;nbsp; But is there another way that avoids the loop?&lt;/P&gt;</description>
      <pubDate>Tue, 14 May 2024 01:35:03 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Identify-Same-Name-Items-in-a-List/m-p/754103#M93619</guid>
      <dc:creator>pmroz</dc:creator>
      <dc:date>2024-05-14T01:35:03Z</dc:date>
    </item>
    <item>
      <title>Re: Identify Same-Name Items in a List</title>
      <link>https://community.jmp.com/t5/Discussions/Identify-Same-Name-Items-in-a-List/m-p/754126#M93621</link>
      <description>&lt;P&gt;Peter,&lt;/P&gt;
&lt;P&gt;There might be a better way to do this,&lt;/P&gt;
&lt;P&gt;(See Stan's response for the correct solution.)&lt;/P&gt;
&lt;P&gt;but here is my solution created at the end of a long day.&amp;nbsp; It takes your Values matrix and creates an Associative array with an entry for each value in the Values matrix that has duplicate values and all of the positions found for the key.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

values = {"ABC", "DEF", "Per", "Per", "Per", "Per", "Per", "XYZ", "UVW"};

dt = New Table( "test", private, New Column( "val", character ) );
dt:val &amp;lt;&amp;lt; set values( values );
array = Associative Array( values );
uniqs = array &amp;lt;&amp;lt; get keys;
For Each( {vals}, uniqs,
	positions = dt &amp;lt;&amp;lt; get rows where( :val == vals );
	If( Length( positions ) &amp;gt; 1,
		array &amp;lt;&amp;lt; insert item( vals, positions ),
		array &amp;lt;&amp;lt; remove item( vals )
	);
);
Close( dt, nosave );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 May 2024 04:07:31 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Identify-Same-Name-Items-in-a-List/m-p/754126#M93621</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2024-05-14T04:07:31Z</dc:date>
    </item>
    <item>
      <title>Re: Identify Same-Name Items in a List</title>
      <link>https://community.jmp.com/t5/Discussions/Identify-Same-Name-Items-in-a-List/m-p/754127#M93622</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/4550"&gt;@pmroz&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could use the &lt;A href="https://www.jmp.com/support/help/en/17.2/index.shtml#page/jmp/loc-functions.shtml" target="_self"&gt;Loc function&lt;/A&gt;--&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;loc(values, "Per" );&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;cheers,&lt;/P&gt;
&lt;P&gt;Stan&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;//:*/&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;values = {"ABC", "DEF", "Per", "Per", "Per", "Per", "Per", "XYZ", "UVW"};&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;loc(values, "Per")&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;/*:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;[3, 4, 5, 6, 7]&lt;/P&gt;</description>
      <pubDate>Tue, 14 May 2024 03:33:01 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Identify-Same-Name-Items-in-a-List/m-p/754127#M93622</guid>
      <dc:creator>stan_koprowski</dc:creator>
      <dc:date>2024-05-14T03:33:01Z</dc:date>
    </item>
    <item>
      <title>Re: Identify Same-Name Items in a List</title>
      <link>https://community.jmp.com/t5/Discussions/Identify-Same-Name-Items-in-a-List/m-p/754128#M93623</link>
      <description>&lt;P&gt;Good solution Stan.&amp;nbsp; Here is your solution incorporated into my code which checks for all repeating values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

values = {"ABC", "DEF", "Per", "Per", "Per", "Per", "Per", "XYZ", "UVW"};

array = Associative Array( values );
uniqs = array &amp;lt;&amp;lt; get keys;
For Each( {vals}, uniqs,
	positions = loc(values, vals);
	If( Length( positions ) &amp;gt; 1,
		array &amp;lt;&amp;lt; insert item( vals, positions ),
		array &amp;lt;&amp;lt; remove item( vals )
	);
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 May 2024 03:39:13 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Identify-Same-Name-Items-in-a-List/m-p/754128#M93623</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2024-05-14T03:39:13Z</dc:date>
    </item>
    <item>
      <title>Re: Identify Same-Name Items in a List</title>
      <link>https://community.jmp.com/t5/Discussions/Identify-Same-Name-Items-in-a-List/m-p/754130#M93625</link>
      <description>&lt;P&gt;If you want only exact matches, before JM18 you could use Loc and in JMP18 &lt;A href="https://www.jmp.com/support/help/en/18.0/#page/jmp/list-functions.shtml?os=win&amp;amp;source=application#ww11158735" target="_self"&gt;Where()&lt;/A&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

values = {"ABC", "DEF", "Per", "Per", "Per", "Per", "Per", "XYZ", "UVW"};

idx1 = Loc(values, "Per"); // Before JMP17
idx2 = Where(values == "Per"); // JMP18

show(idx1, idx2);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also if you need even non-exact matches in JMP18, Where() is able to do that&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

values = {"APerBC", "PerDEF", "Per", "Per", "Per", "Per", "Per", "XYZ", "UVW"};

idx2 = Where(Contains(values, "Per")); // JMP18

show(idx2);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 May 2024 04:40:04 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Identify-Same-Name-Items-in-a-List/m-p/754130#M93625</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-05-14T04:40:04Z</dc:date>
    </item>
    <item>
      <title>Re: Identify Same-Name Items in a List</title>
      <link>https://community.jmp.com/t5/Discussions/Identify-Same-Name-Items-in-a-List/m-p/754131#M93626</link>
      <description>&lt;P&gt;Here is a solution that doesn't require writing any loops. This method works on your example, and also works on multiple, duplicate values without having to identify the duplicate values in the code.&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);

values = {"ABC", "DEF", "Per", "Per", "Per", "Per", "Per", "XYZ", "UVW"};

// make data table with values //
dt = new table("item table" /*, private*/);
dt &amp;lt;&amp;lt; new column("Items", character, nominal, set values(values));


// identify the duplicate rows //
dt &amp;lt;&amp;lt; Select duplicate rows( Match( :Items ) );


// if you also want the first of the duplicate values, otherwise skip the next two lines //
dt &amp;lt;&amp;lt; Go To( :Items );
dt &amp;lt;&amp;lt; Select All Matching Cells();


// save the selected row results //
dupLocations = dt &amp;lt;&amp;lt; get selected rows();


// clean up the data table //
close(dt, no save);



show(dupLocations);




&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 May 2024 05:06:17 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Identify-Same-Name-Items-in-a-List/m-p/754131#M93626</guid>
      <dc:creator>ngambles</dc:creator>
      <dc:date>2024-05-14T05:06:17Z</dc:date>
    </item>
    <item>
      <title>Re: Identify Same-Name Items in a List</title>
      <link>https://community.jmp.com/t5/Discussions/Identify-Same-Name-Items-in-a-List/m-p/754173#M93635</link>
      <description>&lt;P&gt;I thought loc() only worked on numbers.&amp;nbsp; DOH!&amp;nbsp; Great solutions.&lt;/P&gt;
&lt;P&gt;Thanks all!&lt;/P&gt;
&lt;P&gt;-Peter&lt;/P&gt;</description>
      <pubDate>Tue, 14 May 2024 11:14:24 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Identify-Same-Name-Items-in-a-List/m-p/754173#M93635</guid>
      <dc:creator>pmroz</dc:creator>
      <dc:date>2024-05-14T11:14:24Z</dc:date>
    </item>
  </channel>
</rss>

