Group Abstract Group Abstract

Message Boards Message Boards

0
|
5.8K Views
|
3 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Lookup across datasets

Posted 10 years ago

I would like to output the value of "out" that corresponds to a certain value of "in" in the following association:

a = {<|"in" -> 0, "out" -> 1|>, <|"in" -> 1, "out" -> 3|>, <|
   "in" -> 2, "out" -> 4|>}

So for example, I would like to lookup the minimum value of "in" (which is 0 in the above) and get out the associated value of "out" (which is 1 in the above). I can find the minimum value of "in" with:

Min[<|"in" -> #["in"]|> & /@ a]

but, since Lookup refers to the value against the key, not another value in the table, I can't work out how to output the corresponding "out" value.

POSTED BY: Martin Currie
3 Replies
POSTED BY: Martin Currie
Posted 10 years ago

I just notice you wanted the out value for the minimum value of "in" --> you hav eto change the last line above to:

b[Select[#in == b[Min, "in"] &], "out"]
POSTED BY: Michael Helmle
Posted 10 years ago

create a dataset from a

b = Dataset[a]

Build a query for the value of "in"

b[Select[#in == 0 &], "out"]
POSTED BY: Michael Helmle
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard