- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Associative Array from variables
Can somebody help me with a correct syntax to create Associative Array from variables?
Now I have this:
a = {"a1", "a2", "a3"};
b = {"b1", "b2", "b3"};
AB = [
"AA" => a,
"BB" => b
];
AB["AA"];
It returns:
/*:
a
I want it to return:
/*:
{"a1", "a2", "a3"}
I tried different combinations of Eval List(), Eval Expr(), Expr() and Eval(), but no luck.
Thanks!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Associative Array from variables
You almost had it! You need to input the arguments to Associative Array()
as Associative Array( keys, values )
, instead of Associative Array( {keys, values} )
,
a = {"a1", "a2", "a3"};
b = {"b1", "b2", "b3"};
keys = {"AA", "BB"};
values = Eval List({a, b});
AB = Associative Array(keys, values);
AB["AA"];
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Associative Array from variables
AB = Associative Array(EvalList({a, b}))
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Associative Array from variables
This does not produce the desired result. Keep in mind, keys are "AA" and "BB", and values for those keys are lists a and b, respectively.
But it got me on the correct track, so this works as intended:
a = {"a1", "a2", "a3"};
b = {"b1", "b2", "b3"};
keys = {"AA", "BB"};
values = Eval List({a, b});
AB = Associative Array({keys, values});
AB["AA"];
Thanks!
P.S. Actually it doesn't work either.
I can't understand how JMP decides which one to use if my values are lists too??
//Create an associative array from a list that contains two lists of a key-value pair:
map = Associative Array( {{"yes", 0}, {"no", 1}} );
//Create an associative array from a list of keys and a list of values:
map = Associative Array( {"yes", "no"}, {0, 1} );
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Associative Array from variables
Had to go brute force way for now:
AB = Associative Array();
AB["AA"] = Eval List(a);
AB["BB"] = Eval List(b);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Associative Array from variables
You almost had it! You need to input the arguments to Associative Array()
as Associative Array( keys, values )
, instead of Associative Array( {keys, values} )
,
a = {"a1", "a2", "a3"};
b = {"b1", "b2", "b3"};
keys = {"AA", "BB"};
values = Eval List({a, b});
AB = Associative Array(keys, values);
AB["AA"];