Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Is it possible to take advantage of Dataset's Query operator syntax to Merge parallel queries thereby avoiding Function's that are otherwise required?

Using the planets data:

 planets = ExampleData[{"Dataset", "Planets"}];

{moonMasses, nMoons } = {planets[All, "Moons", Median, "Mass"], 
  planets[All, "Moons", Length, "Mass"]}

enter image description here

These queries are nearly equivalent merges:

(1) Merge[{moonMasses // Normal, nMoons // Normal}, List]

enter image description here

(2) planets[All, "Moons", {Median[#], Length[#]} &, "Mass"] // Normal

enter image description here

The values in (1) are unfortunately wrapped in an extra nested list (and further requres normalizing the data as Merge doesn't take Dataset arguments).

(2) is preferred (normalizing here only because 10.0.0 Dataset Format is not usable).

How to avoid using Function in (2), eg, to shorten the query to a syntax similar to:

planets[All, "Moons", {Median, Length}, "Mass"]
share|improve this question
    
Am I wrong to understand from the documentation that your proposed short query syntax should work? –  Rojo Jul 31 at 5:26
    
In the meantime, a subquery seems to work planets[All, "Moons", Query[{Median, Length}], "Mass"] –  Rojo Jul 31 at 5:29
    
@Rojo, that works - I had tried {Query[Median],Query[Length]} but didn't think of this variation. Write it up as an answer, will accept. –  alancalvitti Jul 31 at 5:46
    
This bug is not yet fixed in Mathematica 10.0.1 –  Mr.Wizard Sep 17 at 13:53

1 Answer 1

up vote 9 down vote accepted

Am I wrong to understand from the documentation that your proposed short query syntax should work?

In the meantime, a subquery seems to work planets[All, "Moons", Query[{Median, Length}], "Mass"]

share|improve this answer
2  
planets[All, "Moons", {Median, Length}, "Mass"] should work, because Median and Length on their own are ascending, so {Median, Length} should clearly also be considered to be ascending. Thanks for finding! –  Taliesin Beynon Jul 31 at 17:37
    
@TaliesinBeynon are Apply, or MapIndexed given some special treatment (such as descending operators)? Because I usually find issues with them but they aren't descending –  Rojo Aug 9 at 4:23
1  
It doesn't really make sense for Map to be descending, because Map[f] is really All, f. Apply could be descending, but it's more useful for it be ascending, because it is a useful sugar on top of other ascending functions, e.g. Apply[#1 + #2&] <=> #[[1]] + #[[2]]&. Not sure about MapIndexed. –  Taliesin Beynon Aug 11 at 21:41
1  
@TaliesinBeynon, makes sense, thx. So for example the fact that this doesn't work Dataset[{1}][Apply[f]] but this does Dataset[{1}][Apply[f, #] &] is a simple bug –  Rojo Aug 11 at 22:53
1  
yes, that's a bug. thanks, fixed! –  Taliesin Beynon Aug 11 at 22:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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