Skip to content

Commit

Permalink
perf: Only calculate data group interactions once
Browse files Browse the repository at this point in the history
This goes towards making overall grouped calculations quicker. See #119
  • Loading branch information
nathaneastwood committed Dec 29, 2022
1 parent e910fd7 commit 3cc0a99
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion R/group_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ calculate_groups <- function(data, groups, drop = group_by_drop_default(data)) {
is_factor <- do.call(c, lapply(unique_groups, function(x) is.factor(x)))
n_comb <- nrow(unique_groups)
rows <- rep(list(NA), n_comb)
data_groups <- interaction(data[, groups, drop = TRUE])
for (i in seq_len(n_comb)) {
rows[[i]] <- which(interaction(data[, groups, drop = TRUE]) %in% interaction(unique_groups[i, groups]))
rows[[i]] <- which(data_groups %in% interaction(unique_groups[i, groups]))
}

if (!isTRUE(drop) && any(is_factor)) {
Expand Down

0 comments on commit 3cc0a99

Please sign in to comment.