Message Boards Message Boards

GROUPS:

Alternatives in selection of dataset rows?

Posted 2 months ago
351 Views
|
2 Replies
|
2 Total Likes
|

As an example, suppose I have a table such as

enter image description here

that is in the form of a Mathematica Dataset. In Excel I can select rows with specifications such as column a >.6 and column d either g or h. I am able to figure out how to use Select to specify rows for which column a>.6 and column d equal to g, but I have not been able to find the syntax to specify the alternative of column d equal to g or h. Can anyone help me with the correct command?

Thanks.

2 Replies
Posted 2 months ago

Hi Mike,

Here is one way

SeedRandom[123];
dataset = 
 RandomReal[1, {4, 3}] // 
    MapThread[(Append, {#, {"e", "g", "h", "g"}}] & // 
    Map[AssociationThread[{"a", "b", "c", "d"} -> #] &, #] & // 
    Dataset

dataset[Select[#b > 0.3 && MemberQ[{"g", "h"}, #d] &]]
Posted 2 months ago

Thanks Rohit. That was the information I needed.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract