Extreme Optimization™: Complexity made simple.

Math and Statistics
Libraries for .NET

  • Home
  • Features
    • Math Library
    • Vector and Matrix Library
    • Statistics Library
    • Performance
    • Usability
  • Documentation
    • Introduction
    • Math Library User's Guide
    • Vector and Matrix Library User's Guide
    • Data Analysis Library User's Guide
    • Statistics Library User's Guide
    • Reference
  • Resources
    • Downloads
    • QuickStart Samples
    • Sample Applications
    • Frequently Asked Questions
    • Technical Support
  • Blog
  • Order
  • Company
    • About us
    • Testimonials
    • Customers
    • Press Releases
    • Careers
    • Partners
    • Contact us
Introduction
Deployment Guide
Nuget packages
Configuration
Using Parallelism
Expand Mathematics Library User's GuideMathematics Library User's Guide
Expand Vector and Matrix Library User's GuideVector and Matrix Library User's Guide
Expand Data Analysis Library User's GuideData Analysis Library User's Guide
Expand Statistics Library User's GuideStatistics Library User's Guide
Expand Data Access Library User's GuideData Access Library User's Guide
Expand ReferenceReference
  • Extreme Optimization
    • Features
    • Solutions
    • Documentation
    • QuickStart Samples
    • Sample Applications
    • Downloads
    • Technical Support
    • Download trial
    • How to buy
    • Blog
    • Company
    • Resources
  • Documentation
    • Introduction
    • Deployment Guide
    • Nuget packages
    • Configuration
    • Using Parallelism
    • Mathematics Library User's Guide
    • Vector and Matrix Library User's Guide
    • Data Analysis Library User's Guide
    • Statistics Library User's Guide
    • Data Access Library User's Guide
    • Reference
  • Data Analysis Library User's Guide
    • Indexes
    • Data Frames
    • Data wrangling
    • Grouping and Aggregation
    • Working with Categorical Data
    • Working with Time Series Data
  • Data wrangling
    • Joining and reshaping data frames
    • Transforming columns
    • Sorting And Filtering
  • Sorting And Filtering

Sorting And Filtering

Extreme Optimization Numerical Libraries for .NET Professional

In the previous section, the DataFrameR, C class was introduced as the representation of a data set. This representation favors the column-oriented view: the members of the collection are the variables, usually the columns in a table. In this section, we will look at the row-oriented view. We'll also discuss sorting and filtering.

Sorting

The data in a DataFrameR, C can be sorted by the values of its row index, one or more levels in a hierarchical row index, or one or more columns. For each column, it can be specified whether the result should be in ascending or descending order. All methods that perform sorting return a new data frame.

The simplest way to sort a data frame is on its index. This operation is implemented by the SortByIndex method. An optional argument of type SortOrder indicates whether the rows should be sorted in ascending or descending order. The default is ascending. In the following example, a data frame with a row index of dates is sorted so the dates are in descending order:

C#
VB
C++
F#
Copy
var dates = Index.CreateDateRange(new DateTime(2015, 11, 11), 15, Recurrence.Daily);
var df1 = DataFrame.FromColumns(new Dictionary<string, object>() {
        { "values1", Vector.CreateRandom(dates.Length) },
        { "values2", Vector.CreateRandom(dates.Length) },
        { "values3", Vector.CreateRandom(dates.Length) },
        }, dates);
var df2 = df1.SortByIndex(SortOrder.Descending);
Dim dates = Index.CreateDateRange(New DateTime(2015, 11, 11), 15, Recurrence.Daily)
Dim df1 = DataFrame.FromColumns(New Dictionary(Of String, Object)() From {
     {"values1", Vector.CreateRandom(dates.Length)},
     {"values2", Vector.CreateRandom(dates.Length)},
     {"values3", Vector.CreateRandom(dates.Length)}}, dates)
df1.SortByIndex(SortOrder.Descending)

No code example is currently available or this language may not be supported.

let dates = Index.CreateDateRange(new DateTime(2015, 11, 11), 15, Recurrence.Daily)
let df1 = DataFrame.FromColumns(ofDict
            [
             "values1" => Vector.CreateRandom(dates.Length)
             "values2" => Vector.CreateRandom(dates.Length)
             "values3" => Vector.CreateRandom(dates.Length)
            ], dates)
let df2 = df1.SortByIndex(SortOrder.Descending) 

The SortBy sorts a data frame by the values in a column. This method has multiple overloads. The first overload takes as its only argument the name of the column by which the data is to be sorted. An optional second argument is a SortOrder value which specifies whether to sort the data frame in ascending or in descending order. The default is ascending.

C#
VB
C++
F#
Copy
var df3 = df1.SortBy("values1", SortOrder.Ascending);
df1.SortBy("values1", SortOrder.Ascending)

No code example is currently available or this language may not be supported.

let df3 = df1.SortBy("values1", SortOrder.Ascending)
Advanced sorting

Sorting on multiple columns will be supported in a future version.

Filtering

It is often necessary to perform calculations on a subset of data, based on certain criteria. Filtering is done by indexing the rows of the data frame directly. Filtering always creates a new data frame.

The rows can be specified as a list of integer row indexes, a list of row keys, or a boolean vector where values indicate the row should be retained.

Copyright (c) 2004-2021 ExoAnalytics Inc.

Send comments on this topic to support@extremeoptimization.com

Copyright © 2004-2021, 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 Optimized for Visual Studio logo
are registered trademarks of Microsoft Corporation.