Previous Page Next Page Contents

stats::calc -- apply functions to samples

Introduction

stats::calc(s, ..) applies functions to columns of the sample s.

Call(s)

stats::calc(s, c, f1 <, f2, ..>)
stats::calc(s, [c1, c2, ..], f1 <, f2, ..>)

Parameters

s - a sample of domain type stats::sample.
c, c1, c2, .. - positive integers representing column indices of the sample.
f1, f2, .. - procedures.

Returns

a sample of domain type stats::sample.

Related Functions

stats::tabulate

Details

Example 1

We create a sample of three rows and three columns:

>> stats::sample([[1, a1, b1], [2, a2, b2], [3, a3, b3]])
   
                                1  a1  b1
                                2  a2  b2
                                3  a3  b3

We add and multiply the elements of the columns 2 and 3 by applying the system functions _plus and _mult:

>> stats::calc(%, [2, 3], _plus, _mult)
   
                        1  a1  b1  a1 + b1  a1*b1
                        2  a2  b2  a2 + b2  a2*b2
                        3  a3  b3  a3 + b3  a3*b3

The following call maps each element of the second column of the original sample to its fourth power:

>> stats::calc(%2, 2, x -> x^4)
   
                             1  a1  b1  a1^4
                             2  a2  b2  a2^4
                             3  a3  b3  a3^4

The following call computes the mean values of the rows of the last sample:

>> stats::calc(%, [1, 2, 3, 4], 
               (x1, x2, x3, x4) -> (x1 + x2 + x3 + x4)/4)
            1  a1  b1  a1^4  1/4*a1 + 1/4*b1 + 1/4*a1^4 + 1/4
            2  a2  b2  a2^4  1/4*a2 + 1/4*b2 + 1/4*a2^4 + 1/2
            3  a3  b3  a3^4  1/4*a3 + 1/4*b3 + 1/4*a3^4 + 3/4

The same is achieved by the following call:

>> stats::calc(%2, [1, 2, 3, 4], stats::mean)
            1  a1  b1  a1^4  1/4*a1 + 1/4*b1 + 1/4*a1^4 + 1/4
            2  a2  b2  a2^4  1/4*a2 + 1/4*b2 + 1/4*a2^4 + 1/2
            3  a3  b3  a3^4  1/4*a3 + 1/4*b3 + 1/4*a3^4 + 3/4

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000