Not sure if this will be the post to ask Seth Chandler questions on the topic of Datasets prior to the Webinar, but I’ll give it a try.
While making corrections, I may have answered my questions in this notebook post.
I will use the Titanic example Dataset:
While making corrections, I may have answered my questions in this notebook post.
I will use the Titanic example Dataset:
In[]:=
titanic=ExampleData[{"Dataset","Titanic"}];
Example: GroupBy
Example: GroupBy
Inside Query, GroupBy[“class”] is a valid operation:
In[]:=
Query[GroupBy["class"]]@titanic
Out[]=
However, outside of Query, the same GroupBy expression does not work with the “syntactic sugar” Key-notation:
In[]:=
GroupBy["class"]@titanic
Out[]=
For the GroupBy to work, we should use the Key-notation or Slot-notation instead:
In[]:=
GroupBy[Key["class"]]@titanic
GroupBy[#class&]@titanic
Out[]=
Example: Select
Example: Select
Select only works with the Slot-notation and does not work with the Key-notation; not even inside a Query.
In[]:=
Select[#class=="1st"&]@titanic
In[]:=
Select[Key["class"]=="1st"]@titanic
Out[]=
In[]:=
Query[Select[Key["class"]=="1st"]]@titanic
Out[]=
My question
My question
GroupBy[“class”] “syntatic sugar” notation outside of Query does not work, unless we use the Key- or Slot-notation. I suspect because the expression is otherwise ambiguous.
Select only accepts the Slot-notation, because the predicate required for Select expects a (pure) argument.
Is this correct or is there a difference in the way we should interpret the Key- versus Slot-notation?
Select only accepts the Slot-notation, because the predicate required for Select expects a (pure) argument.
Is this correct or is there a difference in the way we should interpret the Key- versus Slot-notation?