From bf9c9cde85e585bd743a494e3037260f107114b8 Mon Sep 17 00:00:00 2001 From: Martin Chan Date: Fri, 10 Jun 2022 17:03:50 +0100 Subject: [PATCH] feat: add group Id --- R/workpatterns_rank.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/R/workpatterns_rank.R b/R/workpatterns_rank.R index f19d7bf0..ab3b38bd 100644 --- a/R/workpatterns_rank.R +++ b/R/workpatterns_rank.R @@ -119,7 +119,7 @@ workpatterns_rank <- function(data, ## This is run on `signals_df` num_cols <- names(which(sapply(signals_df, is.numeric))) # Get numeric columns - ## Save original `signals_df` before manipulating + ## Save original `signals_df` before manipulating ------------------------ ## Rename `Signals_sent` columns to prevent conflict signals_df_o <- signals_df %>% set_names( @@ -133,7 +133,8 @@ workpatterns_rank <- function(data, .[, (num_cols) := lapply(.SD, function(x) ifelse(x > 0, 1, 0)), .SDcols = num_cols] %>% # Use `mutate()` method .[, `:=`(WeekCount = .N, - PersonCount = dplyr::n_distinct(PersonId)), + PersonCount = dplyr::n_distinct(PersonId), + Id = .GRP), # group id assignment by = num_cols]