Group Data Example (VB.NET)
[VB.NET]
' COPYRIGHT(C), SIMPLEXAR SOFTWARE LIMITED, 2006-2008.
' All rights reserved.
'
' Use of this copyright notice is precautionary only, and does not imply
' publication or disclosure. The content of this work contains confidential
' and proprietary information of Simplexar Software Limited. Any duplication,
' modification, distribution, or disclosure in any form, in whole, or in part,
' is strictly prohibited without express prior written permission.
' Get namespaces.
Imports System
Imports Simplexar.Statsar
Imports Simplexar.Statsar.Filters
' Start namespace.
Namespace Simplexar.Examples.Statsar
' This example illustrates how to group data. When grouping data,
' rows are combined together from the original data to produce a set
' of summary rows.
Module Example
' The application entry point.
Public Sub Main()
Try
RunExample()
Catch exception As Exception
Console.WriteLine(exception)
End Try
Console.WriteLine("Press ENTER to terminate.")
Console.ReadLine()
End Sub
Private Sub RunExample()
' Create sheet.
Dim calculator As New StatsCalculator
Dim sheet As DataSheet = calculator.Sheet
Dim columns As ColumnList = sheet.Columns
columns.Add("Name", GetType(String))
columns.Add("Height", GetType(Double))
columns.Add("Weight", GetType(Double))
columns.Add("Jog", GetType(Boolean))
columns.Add("Tennis", GetType(Boolean))
' Populate data.
Dim rows As RowList = sheet.Rows
rows.Add("Robert", 68, 135, True, True)
rows.Add("George", 67, 180, False, False)
rows.Add("Agatha", 63, 110, False, False)
rows.Add("Sandy", 60, 125, True, True)
rows.Add("Bill", 65, 160, True, False)
Console.WriteLine(sheet)
' Given the above data, suppose we are interested in considering
' two groups of people, those who jog and those who do not jog.
' We can summarize the data above by using a sheet filter. For
' each of these two groups, suppose we wish to calculate the
' number of people in the group, and the average weight.
' The select expressions we are interested in are: "Jog",
' "COUNT(Jog)" and "Mean = MEAN(Weight)". The group expression we
' are interested in is "Jog".
' Configure sheet filter.
Dim filter As New SheetFilter()
Filter.Select("Jog", "COUNT(JOG)", "Mean = MEAN(Weight)")
Filter.GroupBy("Jog")
' Filter data to produce summary.
Dim summarySheet As DataSheet = sheet.Filter(filter)
Console.WriteLine(summarySheet)
End Sub
End Module
End Namespace