> You might like to di something like:
>
> std::vector< std::vector > groups( max(i) ) ;
>
> you'll pay for the traversal of the max, but then you don't need to resize.
I ended up going with:
NumericVector tapply3(NumericVector x, IntegerVector i, Function fun) {
std::map > groups;
NumericVe
That's the one;
You might like to di something like:
std::vector< std::vector > groups( max(i) ) ;
you'll pay for the traversal of the max, but then you don't need to resize.
Calling fun() is going to be costly too (probably what will dominate).
specially because of our internal::try_catch
Ooops, I completely misinterpreted the std::vector API. To insert the
elements I need to do:
for(x_it = x.begin(), i_it = i.begin(); x_it != x.end(); ++x_it, ++i_it) {
int i = *i_it;
if (i > groups.size()) {
groups.resize(i);
}
groups[i - 1].push_back(*x_it);
}
Hadley
Hi all,
I'm attempting to write a simple version of tapply in C++ (see
attached). However, when I run tapply2(1, 1, sum) (which should
return 1), R segfaults. If I run R with gdb, I get the following
stack trace:
#0 0x03942120 in tapply2 (x=@0xbfffda68, i=@0xbfffda58,
fun=@0xbfffda50) at tappl