<?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: Slicing Associative Arrays? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Slicing-Associative-Arrays/m-p/828085#M100983</link>
    <description>&lt;P&gt;good point : ):)&lt;/img&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 18 Jan 2025 06:52:28 GMT</pubDate>
    <dc:creator>hogi</dc:creator>
    <dc:date>2025-01-18T06:52:28Z</dc:date>
    <item>
      <title>Slicing Associative Arrays?</title>
      <link>https://community.jmp.com/t5/Discussions/Slicing-Associative-Arrays/m-p/828071#M100978</link>
      <description>&lt;P&gt;Fox matrix indexing, one can use 0 and get a full slice:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;m = [ 1 2 , 3 4];
m[0,1]; // [1, 3]&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For Data tables this works as well:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;test = new table("test", &lt;BR /&gt;add rows(10), &lt;BR /&gt;new column("col1",Character, set each value({"A","B","C"}[random integer(3)])),&lt;BR /&gt;new column("col2", set each value(random uniform(5))));
test[4,0]&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For lists of lists, this is not possible:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;list= {{"A", 3},{"B", 5}};
list[0,1]&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Sure, there are many lists of lists where such slicing is not possible, like&amp;nbsp;&lt;CODE class=" language-jsl"&gt;{{"A", 3},{"B"}}.&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;On the other hand, there ARE many lists of list that would allow it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Where it gets really interesting: &lt;EM&gt;Associative arrays of associative arrays&lt;/EM&gt;.&lt;BR /&gt;Like with lists, the concept of Associative Arrays is more flexible than what we can do with a matrix or data table - so slicing will not work for them.&amp;nbsp;But like with lists, there ARE Associative arrays where slicing will work ...&lt;/P&gt;&lt;P&gt;Is there a function in JSL, something like &lt;FONT face="courier new,courier"&gt;myAssociativeArray[0, "weight"]&lt;/FONT&gt;, which does this job?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default to Here(1);
dt = Open( "$SAMPLE_DATA/Big Class Families.jmp" );
dt &amp;lt;&amp;lt; Save( "$DOWNLOADS/test.json" );

// for sake of simplicity we accept to lose 1x ROBERT
myIndex=dt[0,"name"]

myAssociativeArray = Associative Array(myIndex,ParseJSON(Load text file ( "$DOWNLOADS/test.json")));
&lt;BR /&gt;// cool, but not what we want
mapToWeight = Transform Each({{key, value}}, aa, value["weight"]);

SliceAssociativeArray= Function({aa, indexname},
	Transform Each({value}, aa &amp;lt;&amp;lt; get values, value[indexname])
);

SliceAssociativeArray(myAssociativeArray ,"weight") //myAssociativeArray [0, "weight"]&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 18 Jan 2025 05:55:34 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Slicing-Associative-Arrays/m-p/828071#M100978</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2025-01-18T05:55:34Z</dc:date>
    </item>
    <item>
      <title>Re: Slicing Associative Arrays?</title>
      <link>https://community.jmp.com/t5/Discussions/Slicing-Associative-Arrays/m-p/828081#M100979</link>
      <description>&lt;P&gt;Different data structures have different uses, for associative array (I think) it means storing unique keys and getting the values for those keys fast (it stores key-value pairs). Transform Each is one good option to use, just change the output&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;weights = Transform Each({{key, value}}, aa, Output("List"), 
	value["weight"]
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 18 Jan 2025 06:27:26 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Slicing-Associative-Arrays/m-p/828081#M100979</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-01-18T06:27:26Z</dc:date>
    </item>
    <item>
      <title>Re: Slicing Associative Arrays?</title>
      <link>https://community.jmp.com/t5/Discussions/Slicing-Associative-Arrays/m-p/828082#M100980</link>
      <description>&lt;P&gt;Another cool trick - very useful :)&lt;/img&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From the useability, I think&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;weights = Transform Each({{key, value}}, aa, Output("List"), 
	value["weight"]
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;	Transform Each({value}, aa &amp;lt;&amp;lt; get values, value["weight"])&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;from the original post are on a comparable value&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;... quite far from &lt;FONT face="courier new,courier"&gt;aa[0, "weight"]&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just imagine that you want to get all the&amp;nbsp;&amp;nbsp;&lt;FONT face="courier new,courier"&gt;aa[0,"2024",0,0,"date"].&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 18 Jan 2025 06:35:03 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Slicing-Associative-Arrays/m-p/828082#M100980</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2025-01-18T06:35:03Z</dc:date>
    </item>
    <item>
      <title>Re: Slicing Associative Arrays?</title>
      <link>https://community.jmp.com/t5/Discussions/Slicing-Associative-Arrays/m-p/828084#M100982</link>
      <description>&lt;P&gt;I'm not sure what this should "query" &lt;FONT face="courier new,courier"&gt;aa[0,"2024",0,0,"date"].&lt;/FONT&gt;If you only wish to get "0" indices, you could store your values to associative array in such a way, that your keys are column names and values are lists of the row values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1); 

dt = open("$SAMPLE_DATA/Big Class.jmp");

aa = Associative Array();
For Each({colname}, dt &amp;lt;&amp;lt; Get Column Names("String"),
	aa[colname] = As List(Column(dt, colname) &amp;lt;&amp;lt; get values);
);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Generally if I want to store my data in table like format which can be accessed like a table, I would just use (private) JMP data table. &lt;/P&gt;</description>
      <pubDate>Sat, 18 Jan 2025 06:48:06 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Slicing-Associative-Arrays/m-p/828084#M100982</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-01-18T06:48:06Z</dc:date>
    </item>
    <item>
      <title>Re: Slicing Associative Arrays?</title>
      <link>https://community.jmp.com/t5/Discussions/Slicing-Associative-Arrays/m-p/828085#M100983</link>
      <description>&lt;P&gt;good point : ):)&lt;/img&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 18 Jan 2025 06:52:28 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Slicing-Associative-Arrays/m-p/828085#M100983</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2025-01-18T06:52:28Z</dc:date>
    </item>
  </channel>
</rss>

