Fill column with values based on another column with keys and associative arrayI did a quick search and couldn't find a solution. I solved it in a pretty complex way some time ago, but was wondering if there is an easier way.
Problem: I have an associative array of a form:
assarr = ["AA" => "AAA", "BB" => "BBB", => "CCC" ];
I have a column "A" that has either "AA", "BB", or something else.
I need to fill column "B" with values based on the associative array and column "A". i.e. for a row with "A" having "AA", "B" should be "AAA" and so on. If "A" has values not in the array, "B" should get the default "CCC".
Based on the fact how easy it is to create an associative array from two columns, there should be equally easy way to fill column based on associative array and another column with keys.
Thanks,
M.
Automation and ScriptingRe: Fill column with values based on another column with keys and associative arrayDo you mean something like this?
Names Default To Here(1);
aa = ["AA" => "AAA", "BB" => "BBB", => "CCC"];
dt = New Table("Untitled",
Add Rows(5),
Compress File When Saved(1),
New Column("Column 1",
Character,
"Nominal",
Set Values({"AA", "BB", "aa", "C", "D"})
)
);
wait(1);
dt << New Column("Column 2", Character, Nominal, << Set Each Value(
aa[:Column 1]
));Re: Fill column with values based on another column with keys and associative arrayHmmm. Yes, this is exactly what I need. Thank you! Somehow I didn't try this rather obvious approach before.