本文整理汇总了C++中DataFrame::inherits方法的典型用法代码示例。如果您正苦于以下问题:C++ DataFrame::inherits方法的具体用法?C++ DataFrame::inherits怎么用?C++ DataFrame::inherits使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataFrame
的用法示例。
在下文中一共展示了DataFrame::inherits方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rbind__impl
//.........这里部分代码省略.........
SEXP source = df.get(j) ;
String name = df_names[j] ;
Collecter* coll = 0;
size_t index = 0 ;
for( ; index < names.size(); index++){
if( name == names[index] ){
coll = columns[index] ;
break ;
}
}
if( ! coll ){
coll = collecter( source, n ) ;
columns.push_back( coll );
names.push_back(name) ;
}
if( coll->compatible(source) ){
// if the current source is compatible, collect
coll->collect( SlicingIndex( k, nrows), source ) ;
} else if( coll->can_promote(source) ) {
// setup a new Collecter
Collecter* new_collecter = promote_collecter(source, n, coll ) ;
// import data from this chunk
new_collecter->collect( SlicingIndex( k, nrows), source ) ;
// import data from previous collecter
new_collecter->collect( SlicingIndex(0, k), coll->get() ) ;
// dispose the previous collecter and keep the new one.
delete coll ;
columns[index] = new_collecter ;
} else if( all_na(source) ) {
// do nothing, the collecter already initialized data with the
// right NA
} else if( coll->is_logical_all_na() ) {
Collecter* new_collecter = collecter( source, n ) ;
new_collecter->collect( SlicingIndex(k, nrows), source ) ;
delete coll ;
columns[index] = new_collecter ;
} else {
std::string column_name(name) ;
stop(
"Can not automatically convert from %s to %s in column \"%s\".",
coll->describe(), get_single_class(source), column_name
) ;
}
}
k += nrows ;
}
int nc = columns.size() ;
int has_id = Rf_isNull(id) ? 0 : 1;
List out(nc + has_id) ;
CharacterVector out_names(nc + has_id) ;
for( int i=0; i<nc; i++){
out[i + has_id] = columns[i]->get() ;
out_names[i + has_id] = names[i] ;
}
// Add vector of identifiers if .id is supplied
if (!Rf_isNull(id)) {
CharacterVector df_names = dots.names() ;
CharacterVector id_col = no_init(n) ;
CharacterVector::iterator it = id_col.begin() ;
for (int i=0; i<ndata; ++i) {
std::fill( it, it + df_nrows[i], df_names[i] ) ;
it += df_nrows[i] ;
}
out[0] = id_col ;
out_names[0] = Rcpp::as<std::string>(id) ;
}
out.attr( "names" ) = out_names ;
set_rownames( out, n ) ;
// infer the classes and extra info (groups, etc ) from the first (#1692)
if( ndata ){
const DataFrameAble& first = chunks[0] ;
if( first.is_dataframe() ){
DataFrame df = first.get() ;
out.attr("class") = df.attr("class") ;
if( df.inherits("grouped_df") ){
out.attr("vars") = df.attr("vars") ;
out = GroupedDataFrame(out).data() ;
}
} else {
out.attr( "class" ) = classes_not_grouped() ;
}
} else {
out.attr( "class" ) = classes_not_grouped() ;
}
return out ;
}