> 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