0
$\begingroup$

For consistency I would like the results of Select and similar operation on Datasets to always return a Dataset object. If you query a Dataset and the result is a single column or a single value a List is returned.

data = {{"ID", "Variable1", "Variable2"}, {"Alpha", 1, 0}, {"Beta", 1,1}, {"Alpha", 1, 0}};
assoc = AssociationThread[First@data -> #] & /@ Rest@data;
ds = Dataset[assoc];

This returns a Dataset

ds[Select[#"ID" == "Alpha" &], {"ID", "Variable1"}]

This returns a List

ds[Select[#"ID" == "Alpha" &], "ID"]
(* Result {Alpha,Alpha} *)

This returns a list

ds[Select[#"ID" == "Beta" &], "ID"]
(* Result {Beta} *)
$\endgroup$
2
$\begingroup$

In 10.0.2 under Windows all three operations return an object with the Head Dataset. I presume you mean that within this Dataset you want Association lists rather than plain lists? Perhaps your goal is achieved with:

ds[Select[#"ID" == "Alpha" &], {"ID"}]

ds[Select[#"ID" == "Beta" &], {"ID"}]

enter image description here

$\endgroup$
  • $\begingroup$ So simple. Didn't think to check the head - took what I could with my eyes as evidence. Nicely done. $\endgroup$ – Gordon Coale Feb 12 '15 at 8:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.