STK++ 0.9.13
STK::DataFrameToArray2D< Type > Class Template Reference

The DataFrameToArray2D class allow to export the data of some TYPE stored in a DataFrame to be exported in an Array2D. More...

#include <STK_DataFrameToArray2D.h>

Public Member Functions

 DataFrameToArray2D (DataFrame const &df)
 Constructor.
 
 ~DataFrameToArray2D ()
 destructor
 
void run ()
 run the export.
 
Array2D< Type > * p_data ()
 Accessor.
 
void release ()
 release the Array2D.
 
void eraseNAValues (bool byRow)
 remove NA values from the Array2D
 

Private Attributes

DataFrame constdf_
 A reference to the DataFrame we want to exprt.
 
Array2D< Type > * p_data_
 A pointer on the 2D Container the class will create.
 

Detailed Description

template<class Type>
class STK::DataFrameToArray2D< Type >

The DataFrameToArray2D class allow to export the data of some TYPE stored in a DataFrame to be exported in an Array2D.

The 2D container is created on the stack and will be deleted with the DataFrameToArray2D structure. It is possible to release the 2D container by calling explicitly the release(). In this case the end user will have to free directly the Array2D.

Definition at line 55 of file STK_DataFrameToArray2D.h.

Constructor & Destructor Documentation

◆ DataFrameToArray2D()

template<class Type >
STK::DataFrameToArray2D< Type >::DataFrameToArray2D ( DataFrame const df)
inline

Constructor.

Parameters
dfthe DataFrame to export

Definition at line 61 of file STK_DataFrameToArray2D.h.

61: df_(df), p_data_(0) {}
Array2D< Type > * p_data_
A pointer on the 2D Container the class will create.
DataFrame const & df_
A reference to the DataFrame we want to exprt.

◆ ~DataFrameToArray2D()

template<class Type >
STK::DataFrameToArray2D< Type >::~DataFrameToArray2D ( )
inline

destructor

Definition at line 63 of file STK_DataFrameToArray2D.h.

63{ if (p_data_) delete p_data_;}

References STK::DataFrameToArray2D< Type >::p_data_.

Member Function Documentation

◆ eraseNAValues()

template<class Type >
void STK::DataFrameToArray2D< Type >::eraseNAValues ( bool  byRow)
inline

remove NA values from the Array2D

Parameters
byRowtrue if the user want to delete the rows with NA values, false if the user want to remove the column with NA values.

Definition at line 95 of file STK_DataFrameToArray2D.h.

96 {
97 // check if there exists data
98 if (!p_data_) return;
99 // get the first index
100 const int firstCol = p_data_->beginCols(), firstRow = p_data_->beginRows();
101 // get the last index
102 int lastCol = p_data_->lastIdxCols(), lastRow = p_data_->lastIdxRows();
103 if (byRow)
104 {
105 // loop on the rows
106 for (int i= firstRow; i <= lastRow; ++i)
107 {
108 bool asNA = false;
109 // loop on the element of the row
110 for (int j= firstCol; j <= lastCol; ++j)
111 {
112 if (Arithmetic<Type>::isNA(p_data_->elt(i,j)))
113 {
114 asNA = true;
115 break;
116 }
117 }
118 // remove current row
119 if (asNA)
120 {
121 p_data_->eraseRows(i);
122 i--;
123 lastRow--;
124 }
125 }
126 }
127 else
128 {
129 // loop on the column
130 for (int j= firstCol; j <= lastCol; ++j)
131 {
132 bool asNA = false;
133 // loop on the element of the column
134 for (int i= firstRow; i <= lastRow; ++i)
135 {
136 if (Arithmetic<Type>::isNA(p_data_->elt(i,j)))
137 {
138 asNA = true;
139 break;
140 }
141 }
142 // remove current column
143 if (asNA)
144 {
145 p_data_->eraseCols(j);
146 j--;
147 lastCol--;
148 }
149 }
150 }
151 }
static bool isNA(Type const &x)

References STK::DataFrameToArray2D< Type >::p_data_.

◆ p_data()

template<class Type >
Array2D< Type > * STK::DataFrameToArray2D< Type >::p_data ( )
inline

Accessor.

get the 2D container. This method is not constant in order to the user to modified directly the 2D container.

Returns
a ptr on the 2D container constructed

Definition at line 88 of file STK_DataFrameToArray2D.h.

88{ return p_data_;}

References STK::DataFrameToArray2D< Type >::p_data_.

◆ release()

template<class Type >
void STK::DataFrameToArray2D< Type >::release ( )
inline

release the Array2D.

It will be freed by the user.

Definition at line 90 of file STK_DataFrameToArray2D.h.

90{ p_data_ =0;}

References STK::DataFrameToArray2D< Type >::p_data_.

◆ run()

template<class Type >
void STK::DataFrameToArray2D< Type >::run ( )
inline

run the export.

Definition at line 65 of file STK_DataFrameToArray2D.h.

66 {
67 p_data_ = new Array2D<Type>();
68 // for each field Try a type conversion
69 for(int iVar = df_.beginCols(); iVar<=df_.lastIdxCols(); iVar++)
70 {
71 IVariable* const p_var = df_.elt(iVar);
72 // if there is a variable
73 if (p_var)
74 {
75 // check the type of the variable
76 if (p_var->getType() == IdTypeImpl<Type>::returnType())
77 {
78 Variable<Type>* p_variable = static_cast<Variable<Type>* >(p_var);
79 p_data_->pushBackCols(*p_variable);
80 }
81 }
82 }
83 }
int beginCols() const
IVariable *& elt(int const &i)
access to an element.
int lastIdxCols() const
static Base::IdType returnType()

References STK::DataFrame::beginCols(), STK::DataFrameToArray2D< Type >::df_, STK::DataFrame::elt(), STK::DataFrame::lastIdxCols(), STK::DataFrameToArray2D< Type >::p_data_, and STK::IdTypeImpl< TYPE >::returnType().

Member Data Documentation

◆ df_

template<class Type >
DataFrame const& STK::DataFrameToArray2D< Type >::df_
private

A reference to the DataFrame we want to exprt.

Definition at line 155 of file STK_DataFrameToArray2D.h.

Referenced by STK::DataFrameToArray2D< Type >::run().

◆ p_data_


The documentation for this class was generated from the following file: