Skip to content

Proposal: averaging multiple values #2078

Open

Description

@mlucy

I'm rewriting our election tutorial to use the new gmr, and it would be waaay nicer if you could write table.group('id').avg('Dem', 'GOP') to get back {Dem: DEM_AVG, GOP: GOP_AVG}.

Activity

  1. added this to the milestone on Mar 11, 2014
  2. coffeemug commented on Mar 11, 2014

    @coffeemug
    Contributor

    Note, this is related to #1725.

  3. modified the milestones: , on Sep 4, 2014
  4. coffeemug commented on Sep 4, 2014

    @coffeemug
    Contributor

    Also note, we should consider doing this for other aggregators.

  5. mlucy commented on Sep 9, 2014

    @mlucy
    MemberAuthor

    I think we should do what I wrote above for avg, sum, min, max, and count.

    There's a small wrinkle, which is that you can pass functions to aggregators as well as field names. I think in that case we should use an ordinal (the offset of the function) as the name in the resulting object. So tbl.group('id').avg(lambda{|row| row['dem']}, lambda {|row| row['gop']}) would return {1: DEM_AVG, 2: GOP_AVG}.

  6. coffeemug commented on Sep 11, 2014

    @coffeemug
    Contributor

    That sounds great, with the exception that ordinals should start at zero, not one. What kind of barbarism is this?!

  7. neumino commented on Sep 11, 2014

    @neumino
    Member

    This partially solves the problem.
    We can't get the sum of a field and the average of another field without manually doing a map/reduce.

    What about adding an aggregator command that would work like this:

    r.table("elector").group("party").aggregate(r.avg("age"), r.count(), r.sum("donations"))
    // returns
    [
      {
        group: <group>,
        reduction: [<average age>, <count>, <sum donations>]
      },
      ...
    ]
  8. mlucy commented on Sep 11, 2014

    @mlucy
    MemberAuthor

    I'm not opposed to adding a way to do arbitrary combinations of reductions, but it's a lot more work (and a much more contentious API discussion). I think that should be a separate issue (e.g. #1725).

    I wouldn't be opposed to ignoring this issue and jus waiting until we have enough time to discuss/implement the more complicated thing.

  9. coffeemug commented on Sep 11, 2014

    @coffeemug
    Contributor

    I still think we should implement this -- it's really useful. I'd like #1725 to go into the next ReQL discussion.

  10. mlucy commented on Sep 19, 2014

    @mlucy
    MemberAuthor

    Marking as settled. We'll do what I said in #2078 (comment) . We'll discuss a more general way to do multiple aggregations in #1725.

    This is lower-priority then some other things since it's just convenient rather than being powerful enough to solve the multiple aggregations problem.

  11. 6 remaining items

  12. modified the milestones: , subsequent on Jan 2, 2015
  13. modified the milestones: 2.1, subsequent, on Mar 24, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions