# 3.3.2.1 Average

Operates on the given dataset to find a running average. This command alters the dataset on which it operates. To find averages for a dataset without altering the original data, use the ave() function.

 Please see the averagexy, avecurves X-Function.

## Syntax:

average [option] dataset [range]

## Note on [range]:

[range] appears in the command syntax line of commands that take a dataset as an argument. It indicates that the range modification options can be used to set the active range of the dataset. The command affects only the active range of the dataset.

There are three range modification options: -b, -e, and -t. They offer two methods of implementation:

Set the beginning and final index numbers of the active range:

-b  firstPoint  -e  endPoint

Set the total number of points in the active range, beginning at firstPoint:

-b firstPoint -t totalPoints

## Options:

### no option; Average neighboring values

Syntax: average string

Each value is the average of three values, the averaged value and its two neighboring values.

range bb = [Book1]Sheet1!1;
ave bb;

### -l; Limit data points by the average of the first and last two points

Syntax: average -l dataset [range]

Find the average of the first two points in dataset and last two points in dataset.If the intervening points (third point through the n-2 point) fall outside the range defined by these two average values, then replace the intervening points with the closer of these two averages. If an intervening point does not fall outside the range defined by these two averages, then leave the value unchanged (see the Examples, below).

### -n; Average 2N neighboring values

Syntax: average -n N dataset [range]

Each value is the average of N points before, N points after and itself.
So, ave -n 1 Col(B) is equivalent to ave Col(B).

range aa = [Book1]Sheet1!2;
ave -n 2 aa;

## Examples:

The following script uses the six neighboring values plus itself (2*3+1) to find the average for each value in col(B).

range aa = [Book1]Sheet1!2;
ave -n 3 aa;

The next script uses the four neighboring values plus itself (2*2+1) to find the average for each value in col(B) over the range of row index 10 to row index 20.

range aa = [Book1]Sheet1!2
ave -n 2 aa -b 10 -e 20;
// 20 - 10 + 1 = 11 so these statements are equivalente
av -n 2 aa -b 10 -t 11;

The last script calculates the averages of the first two points and last two points in col(B). It then replaces the intervening points that are outside the range of average values with the closer of these two averages.

range aa = [Book1]Sheet1!2
ave -l aa;