Home
Products
Support
Blog
Resources
Company
NMath Stats User's Guide
TOC |  Previous |  Next |  Index

2.3 Adding and Removing Columns

The AddColumn() method adds a column to a data frame:

DataFrame df = new DataFrame();
DFNumericColumn col = new DFNumericColumn( "myCol" );
df.AddColumn( col );

NOTE- The AddColumn() method raises a MismatchedSizeException if you attempt to add a column that is not the same length as any existing columns in a data frame.

You can also add all the columns from one data frame to another, optionally copying the data in the columns. For example, assuming df is a data frame, this code adds the columns of df to a new data frame and copies all the column data:

DataFrame df2 = new DataFrame();
df2.AddColumns( df, true ); 

Overloads of AddColumn() and AddColumns() accept ADO.NET DataColumn and DataColumnCollection instances, respectively. If the data frame already contains rows of data, you must also pass in a DataRowCollection of the same Count as the number of rows in the data frame.

InsertColumn() inserts a column at a given column index. This code adds a column in the first position:

DFStringColumn col = new DFStringColumn( "myCol" );


RemoveColumn() removes the column at a given index:

df.RemoveColumn( 3 );

You can also identify a column by name:

df.RemoveColumn( "myCol" );

Because column names are not constrained to be unique, this method will remove all columns in the data frame with the given name.

RemoveAllColumns() removes all columns from a data frame, but preserves the existing row keys. RemoveColumns() removes the columns specified in a given subset or slice.

Clear() method removes all columns and rows from a data frame. CleanCols() returns a new data frame containing only those columns in a data frame that do not contain missing values.

TOC |  Previous |  Next |  Index

Copyright © 2008 CenterSpace Software, LLC. All rights reserved.
All trademarks and registered trademarks mentioned on this web site are the property of their respective owners.
Contact Webmaster