Message Boards Message Boards

0
|
3880 Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Alternatives in selection of dataset rows?

Posted 3 years ago

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.

POSTED BY: Mike Luntz
2 Replies
Posted 3 years 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 BY: Rohit Namjoshi
Posted 3 years ago

Thanks Rohit. That was the information I needed.

POSTED BY: Mike Luntz
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