Extreme Optimization >
User's Guide >
Statistics Library >
Variable Collections >
Key Variables
Extreme Optimization User's Guide
User's Guide
Up: Variable Collections Next: Variable Collections Previous: Variable Collections Contents
Key Variables
Within a data set, there may be one or more variables that can
uniquely identify an observation. These variables act as keys into
the variable collection, and are therefore called key variables. In
the Extreme Optimization Numerical Libraries for .NET,
categorical variables are implemented by the KeyVariable
class.
Constructing key variables
The KeyVariable class has four constructors that
come in two groups.
The first group uses a ICollection as the source of
the data. The first variant has two parameters. The first is a
string that specifies the name of the variable. The second
parameter is an object that implements the ICollection
interface. This includes arrays, array lists, hash tables, and
more. The second variant only takes one parameter: an object that
implements the ICollection interface containing the
data values.
| C# | Copy Code |
string[] dataArray = new string[]
{"Store 1", "Store 2", "Store 3", "Store 4", "Store 5", "Store 6"};
KeyVariable variable1 = new KeyVariable(dataArray);
KeyVariable variable2 = new KeyVariable("Store", dataArray); |
| Visual Basic | Copy Code |
Dim dataArray As String() = New String() _
{"Store 1", "Store 2", "Store 3", "Store 4", "Store 5", "Store 6"}
Dim variable1 As KeyVariable = New KeyVariable("Store", dataArray)
Dim variable2 As KeyVariable = New KeyVariable(dataArray) |
The second pair of constructors uses a DataColumn
as the source of the data. The first variant once again has two
parameters. The first is a string that specifies the name of the
variable. The second parameter is a DataColumn. The
name of the variable is set to the Caption property of
the data column.
| C# | Copy Code |
DataColumn column;
// Connect to a data source and retrieve the column from a DataTable
KeyVariable variable3 = new KeyVariable(column);
KeyVariable variable4 = new KeyVariable("Store", column); |
| Visual Basic | Copy Code |
Dim column As DataColumn
' Connect to a data source and retrieve the column from a DataTable
Dim variable3 As KeyVariable = New KeyVariable("Store", column)
Dim variable4 As KeyVariable = New KeyVariable(column) |
In addition, variables can be created by
VariableCollection objects, by converting numerical
and date/time variables (see a later section on conversions), and
several other means.
Properties and Methods
The Length
property returns the number of observations for the variable.
The GetValue
method returns the value (observation) with the specified index.
The GetKeys
method returns an array of objects containing the key values. A new
array instance is returned on every call. The GetEnumerator
method returns an IEnumerator object that can be used
to iterate through the key values.
Key variables have no descriptive statistics associated with
them.
Up: Variable Collections Next: Variable Collections Previous: Variable Collections Contents
Copyright 2004-2008,
Extreme Optimization. All rights reserved.
Extreme Optimization, Complexity made simple, M#, and M
Sharp are trademarks of ExoAnalytics Inc.
Microsoft, Visual C#, Visual Basic, Visual Studio, Visual
Studio.NET, and the Visual Studio Logo are registered trademarks of Microsoft Corporation