MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

grouping and averaging {x,y} pairs of data

  • To: mathgroup at
  • Subject: [mg37202] grouping and averaging {x,y} pairs of data
  • From: "David E. Burmaster" <deb at>
  • Date: Wed, 16 Oct 2002 14:26:27 -0400 (EDT)
  • Sender: owner-wri-mathgroup at

Dear Fellows in MathGroup,

I have a list of 17,000+ {x,y} pairs of data

	each x value is a positive integer from 1 to 100+

	each y value is a positive real number

As a *short* example, let's consider:

 data = {{3,1},{4,3},{3,2},{1,10},{4,2},{1,6},{5,2},{2,5},{7,1}}

I want to group the data by the x value and report the arithmetic average
of the y values in each group.

For the example, i want to report:

 output = {{1,8},{2,5},{3,1.5},{4,2.5},{5,2},{6,0},{7,1}}

In this example, x=6 does not occur so i report the average y[6] = 0.

Can anyone suggest a way to do this efficiently?/

many thanks

David E. Burmaster, Ph.D.
Alceon Corporation
POBox 382069                 (new Box number effective 1 Sep 2001)
Harvard Square Station
Cambridge, MA 02238-2069     (new ZIP code effective 1 Sep 2001)

Voice	617-864-4300

Email	deb at

  • Prev by Date: Re: Plot problem
  • Next by Date: Re: tensors
  • Previous by thread: Re: Re: c++ book
  • Next by thread: Re: grouping and averaging {x,y} pairs of data