Unix util to add numbers together and average

Glen Turner glen.turner at aarnet.edu.au
Thu Jun 24 03:13:46 CST 2004

On Wed, 2004-06-23 at 17:04, David Newall wrote:

> On zero-length files it produces an error, which is the most correct
> answer that can be given.

Hi David

The _most_correct_ answer for an average of 0 items is "missing", not an

For a simple illustration of the difference consider plotting the daily
averages of a month. An error results in no graph, a missing value
results in the non-missing averages being plotted.

For example, let's say there are no observations on Day 11, then you
want the following plot rather than no plot at all.

      |    X       X       X       X
 mean |   X X     X X     X X     X X
   of |  X   X       X   X   X   X
day's | X     X X     X X     X X
  obs |X       X       X       X
               Day of month

If you are doing enough statistics to care about the difference that's
when you start using a stats language or library. In those languages
there's a careful distinction between "missing" and "error".

In other languages just set the result for whatever works for your needs
(and that might be throwing an error, using 0, or returning an
out-of-range value).

There is a genuine error in both scripts: lines without observation
values (eg: blank lines) contribute to the number of observations. The
short answer for this trivial task is not to produce such lines :-)


Glen Turner         Tel: (08) 8303 3936 or +61 8 8303 3936 
Network Engineer          Email: glen.turner at aarnet.edu.au
Australian Academic & Research Network   www.aarnet.edu.au

More information about the linuxsa mailing list