本文整理汇总了C++中GroupedDataFrame类的典型用法代码示例。如果您正苦于以下问题:C++ GroupedDataFrame类的具体用法?C++ GroupedDataFrame怎么用?C++ GroupedDataFrame使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GroupedDataFrame类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: filter_grouped_single_env
DataFrame filter_grouped_single_env( const GroupedDataFrame& gdf, const List& args, const Environment& env){
const DataFrame& data = gdf.data() ;
CharacterVector names = data.names() ;
SymbolSet set ;
for( int i=0; i<names.size(); i++){
set.insert( Rf_install( names[i] ) ) ;
}
// a, b, c -> a & b & c
Call call( and_calls( args, set ) ) ;
int nrows = data.nrows() ;
LogicalVector test = no_init(nrows);
LogicalVector g_test ;
GroupedCallProxy call_proxy( call, gdf, env ) ;
int ngroups = gdf.ngroups() ;
GroupedDataFrame::group_iterator git = gdf.group_begin() ;
for( int i=0; i<ngroups; i++, ++git){
SlicingIndex indices = *git ;
int chunk_size = indices.size() ;
g_test = call_proxy.get( indices );
check_filter_result(g_test, chunk_size ) ;
for( int j=0; j<chunk_size; j++){
test[ indices[j] ] = g_test[j] ;
}
}
DataFrame res = subset( data, test, names, classes_grouped() ) ;
res.attr( "vars") = data.attr("vars") ;
return res ;
}
示例2: summarise_grouped
SEXP summarise_grouped(const GroupedDataFrame& gdf, List args, const DataDots& dots){
DataFrame df = gdf.data() ;
int nexpr = args.size() ;
int nvars = gdf.nvars() ;
CharacterVector results_names = args.names() ;
check_not_groups(results_names, gdf);
NamedListAccumulator<SEXP> accumulator ;
int i=0;
for( ; i<nvars; i++){
SET_NAMED(gdf.label(i), 2) ;
accumulator.set( PRINTNAME(gdf.symbol(i)), gdf.label(i) ) ;
}
LazyGroupedSubsets subsets(gdf) ;
Shelter<SEXP> __ ;
for( int k=0; k<nexpr; k++, i++ ){
Environment env = dots.envir(k) ;
Result* res = get_handler( args[k], subsets, env ) ;
// if we could not find a direct Result
// we can use a GroupedCalledReducer which will callback to R
if( !res ) res = new GroupedCalledReducer( args[k], subsets, env) ;
SEXP result = __( res->process(gdf) ) ;
SEXP name = results_names[k] ;
accumulator.set( name, result );
subsets.input( Symbol(name), SummarisedVariable(result) ) ;
delete res;
}
return summarised_grouped_tbl_cpp(accumulator, gdf );
}
示例3: filter_grouped_multiple_env
// version of grouped filter when contributions to ... come from several environment
DataFrame filter_grouped_multiple_env( const GroupedDataFrame& gdf, const List& args, const DataDots& dots){
const DataFrame& data = gdf.data() ;
CharacterVector names = data.names() ;
SymbolSet set ;
for( int i=0; i<names.size(); i++){
set.insert( Rf_install( names[i] ) ) ;
}
int nrows = data.nrows() ;
LogicalVector test(nrows, TRUE);
LogicalVector g_test ;
for( int k=0; k<args.size(); k++){
Call call( (SEXP)args[k] ) ;
GroupedCallProxy call_proxy( call, gdf, dots.envir(k) ) ;
int ngroups = gdf.ngroups() ;
GroupedDataFrame::group_iterator git = gdf.group_begin() ;
for( int i=0; i<ngroups; i++, ++git){
SlicingIndex indices = *git ;
int chunk_size = indices.size() ;
g_test = call_proxy.get( indices );
check_filter_result(g_test, chunk_size ) ;
for( int j=0; j<chunk_size; j++){
test[ indices[j] ] = test[ indices[j] ] & g_test[j] ;
}
}
}
DataFrame res = subset( data, test, names, classes_grouped() ) ;
res.attr( "vars") = data.attr("vars") ;
return res ;
}
示例4: summarise_grouped
SEXP summarise_grouped(const GroupedDataFrame& gdf, List args, Environment env){
DataFrame df = gdf.data() ;
int nexpr = args.size() ;
int nvars = gdf.nvars() ;
CharacterVector results_names = args.names() ;
List out(nexpr + nvars) ;
CharacterVector names(nexpr + nvars) ;
int i=0;
for( ; i<nvars; i++){
out[i] = gdf.label(i) ;
SET_NAMED(out[i], 2) ;
names[i] = CHAR(PRINTNAME(gdf.symbol(i))) ;
}
LazyGroupedSubsets subsets(gdf) ;
for( int k=0; k<nexpr; k++, i++ ){
Result* res( get_handler( args[k], subsets ) ) ;
// if we could not find a direct Result
// we can use a GroupedCalledReducer which will callback to R
if( !res ) res = new GroupedCalledReducer( args[k], gdf, env) ;
out[i] = res->process(gdf) ;
names[i] = results_names[k] ;
delete res;
}
return summarised_grouped_tbl_cpp(out, names, gdf );
}
示例5: filter_grouped
DataFrame filter_grouped( const GroupedDataFrame& gdf, List args, Environment env){
// a, b, c -> a & b & c
Language call = and_calls( args ) ;
const DataFrame& data = gdf.data() ;
int nrows = data.nrows() ;
LogicalVector test = no_init(nrows);
LogicalVector g_test ;
GroupedCallProxy call_proxy( call, gdf, env ) ;
int ngroups = gdf.ngroups() ;
GroupedDataFrame::group_iterator git = gdf.group_begin() ;
for( int i=0; i<ngroups; i++, ++git){
SlicingIndex indices = *git ;
g_test = call_proxy.get( indices );
int chunk_size = indices.size() ;
for( int j=0; j<chunk_size; j++){
test[ indices[j] ] = g_test[j] ;
}
}
DataFrame res = subset( data, test, data.names(), classes_grouped() ) ;
res.attr( "vars") = data.attr("vars") ;
return res ;
}
示例6: symbols
GroupedDataFrame::GroupedDataFrame(DataFrame x, const GroupedDataFrame& model):
data_(x),
symbols(model.get_vars()),
groups(build_index_cpp(data_, model.get_vars())),
nvars_(symbols.size())
{
set_groups(data_, groups);
}
示例7: grouped_indices_grouped_df_impl
// [[Rcpp::export]]
IntegerVector grouped_indices_grouped_df_impl(GroupedDataFrame gdf) {
int n=gdf.nrows();
IntegerVector res = no_init(n);
int ngroups = gdf.ngroups();
GroupedDataFrameIndexIterator it = gdf.group_begin();
for (int i=0; i<ngroups; i++, ++it) {
SlicingIndex index = *it;
int n_index = index.size();
for (int j=0; j<n_index; j++) {
res[ index[j] ] = i + 1;
}
}
return res;
}
示例8: check_not_groups
void check_not_groups(const LazyDots& dots, const GroupedDataFrame& gdf) {
int n = dots.size();
for (int i=0; i<n; i++) {
if (gdf.has_group(dots[i].name()))
stop("cannot modify grouping variable");
}
}
示例9: reldist_impl
//[[Rcpp::export]]
DataFrame reldist_impl(GroupedDataFrame x, GroupedDataFrame y) {
std::vector<float> rel_distances ;
std::vector<int> indices_x ;
DataFrame df_x = x.data() ;
PairedGroupApply(x, y, reldist_grouped, std::ref(indices_x), std::ref(rel_distances));
DataFrame subset_x = DataFrameSubsetVisitors(df_x, names(df_x)).subset(indices_x, "data.frame");
auto ncol_x = subset_x.size() ;
CharacterVector names(ncol_x + 1) ;
CharacterVector names_x = subset_x.attr("names") ;
List out(ncol_x + 1) ;
// x names, data
for( int i=0; i<ncol_x; i++) {
names[i] = names_x[i] ;
out[i] = subset_x[i] ;
}
out[ncol_x] = rel_distances ;
names[ncol_x] = "reldist" ;
out.attr("names") = names ;
out.attr("class") = classes_not_grouped() ;
auto nrows = subset_x.nrows() ;
set_rownames(out, nrows) ;
return out ;
}
示例10: check_not_groups
void check_not_groups(const QuosureList& quosures, const GroupedDataFrame& gdf) {
int n = quosures.size();
for (int i = 0; i < n; i++) {
if (gdf.has_group(quosures[i].name()))
stop("cannot modify grouping variable");
}
}
示例11: check_not_groups
void check_not_groups(const CharacterVector& result_names, const GroupedDataFrame& gdf){
int n = result_names.size() ;
for( int i=0; i<n; i++){
if( gdf.has_group( result_names[i] ) )
stop( "cannot modify grouping variable" ) ;
}
}
示例12: filter_grouped_multiple_env
// version of grouped filter when contributions to ... come from several environment
DataFrame filter_grouped_multiple_env( const GroupedDataFrame& gdf, const LazyDots& dots){
const DataFrame& data = gdf.data() ;
CharacterVector names = data.names() ;
SymbolSet set ;
for( int i=0; i<names.size(); i++){
set.insert( Rf_install( names[i] ) ) ;
}
int nrows = data.nrows() ;
LogicalVector test(nrows, TRUE);
LogicalVector g_test ;
for( int k=0; k<dots.size(); k++){
Rcpp::checkUserInterrupt() ;
const Lazy& lazy = dots[k] ;
Call call( lazy.expr() ) ;
GroupedCallProxy<GroupedDataFrame> call_proxy( call, gdf, lazy.env() ) ;
int ngroups = gdf.ngroups() ;
GroupedDataFrame::group_iterator git = gdf.group_begin() ;
for( int i=0; i<ngroups; i++, ++git){
SlicingIndex indices = *git ;
int chunk_size = indices.size() ;
g_test = check_filter_logical_result(call_proxy.get( indices ));
if( g_test.size() == 1 ){
if( g_test[0] != TRUE ){
for( int j=0; j<chunk_size; j++){
test[indices[j]] = FALSE ;
}
}
} else {
check_filter_result(g_test, chunk_size ) ;
for( int j=0; j<chunk_size; j++){
if( g_test[j] != TRUE ){
test[ indices[j] ] = FALSE ;
}
}
}
}
}
DataFrame res = subset( data, test, names, classes_grouped<GroupedDataFrame>() ) ;
res.attr( "vars") = data.attr("vars") ;
return res ;
}
示例13: filter_grouped_single_env
DataFrame filter_grouped_single_env( const GroupedDataFrame& gdf, const LazyDots& dots){
typedef GroupedCallProxy<GroupedDataFrame, LazyGroupedSubsets> Proxy ;
Environment env = dots[0].env() ;
const DataFrame& data = gdf.data() ;
CharacterVector names = data.names() ;
SymbolSet set ;
for( int i=0; i<names.size(); i++){
set.insert( Rf_install( names[i] ) ) ;
}
// a, b, c -> a & b & c
Call call( and_calls( dots, set, env ) ) ;
int nrows = data.nrows() ;
LogicalVector test(nrows, TRUE);
LogicalVector g_test ;
Proxy call_proxy( call, gdf, env ) ;
int ngroups = gdf.ngroups() ;
GroupedDataFrame::group_iterator git = gdf.group_begin() ;
for( int i=0; i<ngroups; i++, ++git){
SlicingIndex indices = *git ;
int chunk_size = indices.size() ;
g_test = check_filter_logical_result( call_proxy.get( indices ) ) ;
if( g_test.size() == 1 ){
int val = g_test[0] == TRUE ;
for( int j=0; j<chunk_size; j++){
test[ indices[j] ] = val ;
}
} else {
check_filter_result(g_test, chunk_size ) ;
for( int j=0; j<chunk_size; j++){
if( g_test[j] != TRUE ) test[ indices[j] ] = FALSE ;
}
}
}
DataFrame res = subset( data, test, names, classes_grouped<GroupedDataFrame>() ) ;
res.attr( "vars") = data.attr("vars") ;
return res ;
}
示例14: mutate_grouped
SEXP mutate_grouped(GroupedDataFrame gdf, List args, Environment env){
const DataFrame& df = gdf.data() ;
int nexpr = args.size() ;
CharacterVector results_names = args.names() ;
GroupedCallProxy proxy(gdf, env) ;
Shelter<SEXP> __ ;
for( int i=0; i<nexpr; i++){
proxy.set_call( args[i] );
boost::scoped_ptr<Gatherer> gather( gatherer( proxy, gdf ) );
proxy.input( results_names[i], __( gather->collect() ) ) ;
}
DataFrame res = structure_mutate( proxy, df, results_names, classes_grouped() ) ;
res.attr( "vars") = df.attr("vars") ;
res.attr( "labels" ) = df.attr("labels" );
res.attr( "index") = df.attr("index") ;
return res ;
}
示例15: complement_impl
//[[Rcpp::export]]
DataFrame complement_impl(GroupedDataFrame gdf, DataFrame genome) {
genome_map_t chrom_sizes = makeChromSizes(genome) ;
DataFrame df = gdf.data() ;
IntegerVector starts = df["start"] ;
IntegerVector ends = df["end"] ;
CharacterVector chroms = df["chrom"] ;
std::vector<std::string> chroms_out ;
std::vector<int> starts_out ;
std::vector<int> ends_out ;
int ngroups = gdf.ngroups() ;
GroupedDataFrame::group_iterator git = gdf.group_begin() ;
for (int i = 0; i < ngroups; ++i, ++git) {
SlicingIndex indices = *git ;
int ni = indices.size() ;
int start, end ;
int last_end = 1 ;
// get chrom from first index
auto chrom = as<std::string>(chroms[indices[0]]) ;
for (int j = 0; j < ni; ++j) {
start = starts[indices[j]] ;
end = ends[indices[j]] ;
if (j == 0) {
if (start == 1) {
last_end = end ;
continue ;
} else {
chroms_out.push_back(chrom) ;
starts_out.push_back(1) ;
ends_out.push_back(start) ;
}
} else {
chroms_out.push_back(chrom) ;
starts_out.push_back(last_end) ;
ends_out.push_back(start) ;
}
last_end = end;
}
auto chrom_size = chrom_sizes[chrom] ;
if (last_end < chrom_size) {
chroms_out.push_back(chrom) ;
starts_out.push_back(last_end) ;
ends_out.push_back(chrom_size) ;
}
}
return DataFrame::create(_("chrom") = chroms_out,
_("start") = starts_out,
_("end") = ends_out,
_("stringsAsFactors") = false) ;
}