indices#
Purpose#
Processes a set of variable names or indices and returns a vector of variable names and a vector of indices.
Format#
- { name, indx } = indices(dataset, vars)#
- Parameters:
dataset (string) – the name of the dataset.
vars (Nx1 vector) – a character vector of names or a numeric vector of column indices. If scalar 0, all variables in the dataset will be selected.
- Returns:
varnames (Nx1 character vector) – the names associated with vars.
indx (Nx1 numeric vector) – the column indices associated with vars.
Examples#
Find indices for selection of variables#
// Create character vector of variable names
vars = { mpg, weight };
// Create filename
filename = getGAUSSHome("examples/auto.dat");
// Get indices and names of variables
{varnames, ind } = indices(filename, vars);
// Print variables names
print "Variable names:" $varnames;
// Print variable indices
print "Variable indices:" ind;
This produces the following output:
Variable names:
mpg
weight
Variable indices:
3.0000000
7.0000000
Find indices for all variables#
/*
** Set vars equal to zero to get
** indices for all variables
*/
vars =0;
// Create filename
filename = getGAUSSHome("examples/auto.dat");
// Get indices and names of variables
{varnames, ind } = indices(filename, vars);
// Print variables names
print "Variable names:" $varnames;
// Print variables indices
print "Variable indices:" ind;
This produces the following output
Variable names:
make
price
mpg
rep78
headroom
trunk
weight
length
turn
displace
gear_rat
foreign
Variable indices:
1.0000000
2.0000000
3.0000000
4.0000000
5.0000000
6.0000000
7.0000000
8.0000000
9.0000000
10.000000
11.000000
12.000000
Remarks#
If an error occurs, indices()
will either return a scalar error code or
terminate the program with an error message, depending on the trap
state. If the low order bit of the trap flag is 0, indices()
will
terminate with an error message. If the low order bit of the trap flag
is 1, indices()
will return an error code. The value of the trap flag can
be tested with trapchk; the return from indices()
can be tested with
scalerr()
. You only need to check one argument; they will both be the
same. The following error codes are possible:
1 |
Can’t open dataset. |
2 |
Index of variable out of range, or undefined data set variables. |
Source#
indices.src