3.5.3.1.32 Sum

Description

The sum function returns a range whose ith element is (a) the sum of the first i elements of a dataset or (b) the sum of row elements across columns.

Syntax

There are two supported syntaxes:

sum(vd) // operates on a worksheet column of data

Note that sum(vd) automatically assigns values to the sum object (see below).

Alternately, ...

sum(WorksheetName, col1, col2); // operates on rows, from col1 to col2

This syntax does not assign values to the sum object but does create a number of temporary datasets that store certain row-wise statistics (see below).

Parameters

vd

a vector, can be a dataset or Origin worksheet column.

WorksheetName

the worksheet name that contains column col1 and col2.

col1, col2

the column index

Return

For syntax

sum(vd)

Returns a dataset whose ith element is the sum of the first i elements of the dataset vd. The sum(vd) syntax also automatically assigns values to the following Sum object properties:

  sum.mean
  sum.total
  sum.min
  sum.max
  sum.imax
  sum.imin
  sum.sd
  sum.n

For syntax

sum(WorksheetName, col1, col2);

Returns a dataset of sums by row from col1 to col2. Temporary datasets are also created to hold several related values generated by this syntax: _mean, _sd, _max, _min, _range, _npts.

Examples

In this example, col(A) contains 4 values (1, 2, 3, 4). The sum() function returns the dataset (1, 3, 6, 10) where the second value in the returned range (3), is the sum of the first two values in col(A). The last value in the returned range (10) is the sum of all the values in col(A). The value of 10 is also returned in sum.total.

col(A) = {1, 2, 3, 4};
sum(col(A));
// To see the values in the returned dataset sum(col(A))
col(B) = sum(col(A));
// Column B should have values 1, 3, 6, 10
range aa=[book2]sheet1!col(B); // assigns values in Book2, Sheet1, Col(B) to range variable aa
sum(aa); // pass aa to the sum() function
sum.mean=; // return the mean value of aa
// Prepare two columns of data in Book1 Sheet1
col(A) = {1, 2, 3, 4};
col(B) = {3, 4, 5, 6};

// Return the total by row across columns A and B and put values in column C
col(C) = sum([Book1]Sheet1!, 1, 2);

// Return the mean by row across A and B and put values in column D
col(D) = _mean;

In the following example, the user has X values in col(A) and Y values in col(B) and wants to return the X value corresponding to the max Y value.

sum(col(B)); 
col(A)[sum.imax]=;

// another solution ...
table(col(B), col(A), max(col(B)))=;

See Also

Sum Object, Max, Mean, Median, Min, StdDev, StdDevP, Total, Table, Xindex, Xvalue