Skip to content

Commit

Permalink
type: <fix> message: <require the group variable when needed>
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmoy28 committed Dec 21, 2023
1 parent 1cae3f3 commit e89a443
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
6 changes: 6 additions & 0 deletions R/center_group_mean.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
center_group_mean = function(data,cols,group,keep_original=TRUE){
cols = enquo(cols)
group = enquo(group)

group_num = data %>% dplyr::select(!!enquo(group)) %>% names %>% length()
if (group_num == 0) {
stop('Group variable need to be specified')
}
original_df = data %>% dplyr::select(!!cols)
return_df = data %>%
dplyr::group_by(dplyr::across(!!group)) %>%
Expand All @@ -32,3 +37,4 @@ center_group_mean = function(data,cols,group,keep_original=TRUE){
}
return(return_df)
}
center_group_mean(iris,where(is.numeric),group = Species)
7 changes: 6 additions & 1 deletion R/center_mlm.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ center_mlm = function(data,cols,group,keep_original = TRUE){
cols = data %>% dplyr::select(!!enquo(cols)) %>% names()
group = enquo(group)
group_name = data %>% dplyr::select(!!enquo(group)) %>% names()


group_num = group_name %>% length()
if (group_num == 0) {
stop('Group variable need to be specified')
}

# aggregate mean
mean_data = data %>%
dplyr::group_by(dplyr::across(!!group)) %>%
Expand Down
5 changes: 4 additions & 1 deletion R/z_score_mlm_categorical.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ z_scored_mlm_categorical = function(data,cols,dummy_coded = NA,group,keep_origin
dummy_coded = data %>% dplyr::select(!!enquo(dummy_coded)) %>% names()
group = enquo(group)
group_name = data %>% dplyr::select(!!enquo(group)) %>% names()

group_num = group_name %>% length()
if (group_num == 0) {
stop('Group variable need to be specified')
}

# aggregated group mean
mean_data = data %>%
Expand Down
4 changes: 4 additions & 0 deletions R/z_scored_group_mean.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
z_scored_group_mean = function(data,cols,group,keep_original=TRUE) {
cols = enquo(cols)
group = enquo(group)
group_num = data %>% dplyr::select(!!enquo(group)) %>% names %>% length()
if (group_num == 0) {
stop('Group variable need to be specified')
}
original_df = data %>% dplyr::select(!!cols)

return_df = data %>%
Expand Down
5 changes: 4 additions & 1 deletion R/z_scored_mlm.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ z_scored_mlm = function(data,cols,group,keep_original = TRUE){
cols = data %>% dplyr::select(!!enquo(cols)) %>% names()
group = enquo(group)
group_name = data %>% dplyr::select(!!enquo(group)) %>% names()

group_num = group_name %>% length()
if (group_num == 0) {
stop('Group variable need to be specified')
}
mean_data = data %>%
dplyr::group_by(dplyr::across(!!group)) %>%
dplyr::summarise(dplyr::across(!!cols,~mean(.,na.rm = TRUE))) %>%
Expand Down

0 comments on commit e89a443

Please sign in to comment.