<?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: If I have two lists, how can I associate the nth element of one list to the nth element of the other array? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/If-I-have-two-lists-how-can-I-associate-the-nth-element-of-one/m-p/515498#M74220</link>
    <description>&lt;P&gt;If you are thinking purely in terms of lists then the index associates them i.e. if you want the i'th element of both lists then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;value1 = lst1[i];
value2 = lst2[i];&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to think in terms of associative arrays then the 2 lists can be used to create an array&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;arr = AssociativeArray(lst1,lst2);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then presumably you want to use the value from one list to reference the other e.g.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;key = lst1[i];
value = arr[key];&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then to iterate, something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;keys = arr &amp;lt;&amp;lt; get keys;
for (i=1,i&amp;lt;=nitems(keys),i++,
    key = keys[i];
    value = arr[key];
    show(key,value);
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = open("$SAMPLE_DATA/Big Class.jmp");

lst1 = dt:name &amp;lt;&amp;lt; get values;
lst2 = dt:age &amp;lt;&amp;lt; get values;

arr = AssociativeArray(lst1,lst2);

keys = arr &amp;lt;&amp;lt; get keys;
for (i=1,i&amp;lt;=nitems(keys),i++,
    key = keys[i];
    value = arr[key];
    show(key,value);
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 29 Jun 2022 10:43:45 GMT</pubDate>
    <dc:creator>David_Burnham</dc:creator>
    <dc:date>2022-06-29T10:43:45Z</dc:date>
    <item>
      <title>If I have two lists, how can I associate the nth element of one list to the nth element of the other array?</title>
      <link>https://community.jmp.com/t5/Discussions/If-I-have-two-lists-how-can-I-associate-the-nth-element-of-one/m-p/515465#M74216</link>
      <description>&lt;P&gt;How can I associate the nth element of one of the lists to the nth element of another list? I was looking into associative arrays but im unsure on how to actually loop through them and associate each key with the values. (Note that my keys would be in one list and the data in the other list).&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 17:02:48 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/If-I-have-two-lists-how-can-I-associate-the-nth-element-of-one/m-p/515465#M74216</guid>
      <dc:creator>Andyon98</dc:creator>
      <dc:date>2023-06-09T17:02:48Z</dc:date>
    </item>
    <item>
      <title>Re: If I have two lists, how can I associate the nth element of one list to the nth element of the other array?</title>
      <link>https://community.jmp.com/t5/Discussions/If-I-have-two-lists-how-can-I-associate-the-nth-element-of-one/m-p/515495#M74219</link>
      <description>&lt;P&gt;I think you're on the right track; associative arrays would work.&amp;nbsp; Does the example below help?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

list1={"A","B","C","D"};
list2={5,6,7,8};

aa = Associative Array( list1, list2 );

Show(aa[list1[2]]);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Jun 2022 10:40:15 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/If-I-have-two-lists-how-can-I-associate-the-nth-element-of-one/m-p/515495#M74219</guid>
      <dc:creator>HadleyMyers</dc:creator>
      <dc:date>2022-06-29T10:40:15Z</dc:date>
    </item>
    <item>
      <title>Re: If I have two lists, how can I associate the nth element of one list to the nth element of the other array?</title>
      <link>https://community.jmp.com/t5/Discussions/If-I-have-two-lists-how-can-I-associate-the-nth-element-of-one/m-p/515498#M74220</link>
      <description>&lt;P&gt;If you are thinking purely in terms of lists then the index associates them i.e. if you want the i'th element of both lists then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;value1 = lst1[i];
value2 = lst2[i];&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to think in terms of associative arrays then the 2 lists can be used to create an array&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;arr = AssociativeArray(lst1,lst2);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then presumably you want to use the value from one list to reference the other e.g.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;key = lst1[i];
value = arr[key];&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then to iterate, something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;keys = arr &amp;lt;&amp;lt; get keys;
for (i=1,i&amp;lt;=nitems(keys),i++,
    key = keys[i];
    value = arr[key];
    show(key,value);
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = open("$SAMPLE_DATA/Big Class.jmp");

lst1 = dt:name &amp;lt;&amp;lt; get values;
lst2 = dt:age &amp;lt;&amp;lt; get values;

arr = AssociativeArray(lst1,lst2);

keys = arr &amp;lt;&amp;lt; get keys;
for (i=1,i&amp;lt;=nitems(keys),i++,
    key = keys[i];
    value = arr[key];
    show(key,value);
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Jun 2022 10:43:45 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/If-I-have-two-lists-how-can-I-associate-the-nth-element-of-one/m-p/515498#M74220</guid>
      <dc:creator>David_Burnham</dc:creator>
      <dc:date>2022-06-29T10:43:45Z</dc:date>
    </item>
    <item>
      <title>Re: If I have two lists, how can I associate the nth element of one list to the nth element of the other array?</title>
      <link>https://community.jmp.com/t5/Discussions/If-I-have-two-lists-how-can-I-associate-the-nth-element-of-one/m-p/515505#M74221</link>
      <description>&lt;P&gt;This helps big time, thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2022 10:53:03 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/If-I-have-two-lists-how-can-I-associate-the-nth-element-of-one/m-p/515505#M74221</guid>
      <dc:creator>Andyon98</dc:creator>
      <dc:date>2022-06-29T10:53:03Z</dc:date>
    </item>
    <item>
      <title>Re: If I have two lists, how can I associate the nth element of one list to the nth element of the other array?</title>
      <link>https://community.jmp.com/t5/Discussions/If-I-have-two-lists-how-can-I-associate-the-nth-element-of-one/m-p/515515#M74223</link>
      <description>&lt;P&gt;Hi David,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you use associative arrays for three parameters? I tried it and it worked for two but the third parameter just created its own list at the end. How can I associate it with each associative element?&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2022 11:27:15 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/If-I-have-two-lists-how-can-I-associate-the-nth-element-of-one/m-p/515515#M74223</guid>
      <dc:creator>Andyon98</dc:creator>
      <dc:date>2022-06-29T11:27:15Z</dc:date>
    </item>
    <item>
      <title>Re: If I have two lists, how can I associate the nth element of one list to the nth element of the other array?</title>
      <link>https://community.jmp.com/t5/Discussions/If-I-have-two-lists-how-can-I-associate-the-nth-element-of-one/m-p/515527#M74225</link>
      <description>&lt;P&gt;No you can't, they work as key-value pairs.&amp;nbsp; I think you need to maintain multiple arrays of there are additional values that you need to track.&amp;nbsp; I usually end up with a collection of arrays: arrName, arrLSL, arrUSL etc.&amp;nbsp; Although list elements can be anything, so as an example, with specs I will have an arrangement like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;specs = arrSpecs[parameter];
lsl = specs["lsl"];
usl = specs["usl"];&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;i.e. arrSpecs is an array with keys based on parameter name; but the value is another array, with keys "lsl" and "usl".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2022 11:47:55 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/If-I-have-two-lists-how-can-I-associate-the-nth-element-of-one/m-p/515527#M74225</guid>
      <dc:creator>David_Burnham</dc:creator>
      <dc:date>2022-06-29T11:47:55Z</dc:date>
    </item>
  </channel>
</rss>

