-
Notifications
You must be signed in to change notification settings - Fork 2.1k
FR: group_indices() should also return vector of group representatives #2121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
So the "representative" are 1-based indices of the first row in the data that belong to this group ? @krlmlr. In that case, we can easily update // [[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) {
const SlicingIndex& index = *it;
int n_index = index.size();
for (int j = 0; j < n_index; j++) {
res[ index[j] ] = i + 1;
}
}
return res;
} |
Need to be careful when doing #341 because empty groups won't have representatives. They can be |
Good catch. For 1-based representatives, iris[NA_integer_, ]
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> NA NA NA NA NA <NA>
iris[0, ]
#> [1] Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> <0 rows> (or 0-length row.names)
|
We don't need this anymore as we have
|
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/ |
perhaps as an attribute. This will allow simplifying and accelerating tidyr::nest().
Example:
The text was updated successfully, but these errors were encountered: