From c93155f3e597f1a48b961515533050ee549c5611 Mon Sep 17 00:00:00 2001 From: Frank Mu <41923525+fxqmu@users.noreply.github.com> Date: Tue, 6 Feb 2024 09:31:41 -0500 Subject: [PATCH] Update step_dues.R Simplify logic and account for new `ItemDescription` categories in `Dues` dataset. --- R/step_dues.R | 50 ++++++++++++++------------------------------------ 1 file changed, 14 insertions(+), 36 deletions(-) diff --git a/R/step_dues.R b/R/step_dues.R index 5be0aca..c26f76f 100644 --- a/R/step_dues.R +++ b/R/step_dues.R @@ -16,42 +16,19 @@ step_dues <- function(df, year) { mutate( Membership_Dues = case_when( - ItemDescription == "Associate Dues" ~ 'Associate', - ItemDescription == "Associate Returning Dues" ~ 'Associate', - ItemDescription == "Associate Renewal Dues" ~ 'Associate', - ItemDescription == "Fellow Dues" ~ 'Fellow', - ItemDescription == "Fellow Renewal Dues" ~ 'Fellow', - ItemDescription == "Fellow Returning Dues" ~ 'Fellow', - ItemDescription == "International Affiliate Dues" ~ 'International Affiliate', - ItemDescription == "International Affiliate Renewal Dues" ~ 'International Affiliate', - ItemDescription == "New International Affiliate Dues" ~ 'International Affiliate', - ItemDescription == "Member Dues" ~ 'Member', - ItemDescription == "Member Renewal Dues" ~ 'Member', - ItemDescription == "Member Returning Dues" ~ 'Member', - ItemDescription == "New Associate Dues" ~ 'Associate', - ItemDescription == "New Member Dues" ~ 'Member', - ItemDescription == "New Student Affiliate Dues" ~ 'Student Affiliate', - ItemDescription == "New Student Dues" ~ 'Student Affiliate', - ItemDescription == "Pathway Upgrade to Member From Associate" ~ 'Member', - ItemDescription == "Retired Associate Dues" ~ 'Associate', - ItemDescription == "Retired Associate Renewal Dues" ~ 'Retired Associate', - ItemDescription == "Retired Associate Returning Dues" ~ 'Retired Associate', - ItemDescription == "Retired Dues" ~ 'Retired Member', - ItemDescription == "Retired Fellow Dues" ~ 'Retired Fellow', - ItemDescription == "Retired Fellow Renewal Dues" ~ 'Retired Fellow', - ItemDescription == "Retired Fellow Returning Dues" ~ 'Retired Fellow', - ItemDescription == "Retired International Affiliate Dues" ~ 'Retired International Affiliate', - ItemDescription == "Retired International Affiliate Renewal Dues" ~ 'Retired International Affiliate', - ItemDescription == "Retired Member Dues" ~ 'Retired Member', - ItemDescription == "Retired Member Renewal Dues" ~ 'Retired Member', - ItemDescription == "Retired Member Returning Dues" ~ 'Retired Member', - ItemDescription == "Student Affiliate Dues" ~ 'Student Affiliate', - ItemDescription == "Student Affiliate Renewal Dues" ~ 'Student Affiliate', - ItemDescription == "Student Affiliate Returning Dues" ~ 'Student Affiliate', - ItemDescription == "Upgrade to Associate from Student" ~ 'Associate', - ItemDescription == "Upgrade to Member from Associate" ~ 'Member', - ItemDescription == "Upgrade to Member from International Affiliate" ~ 'Member', - ItemDescription == "Upgrade to Member from Student" ~ 'Member' + str_detect(ItemDescription, "Retired") & str_detect(ItemDescription, "International") ~ "Retired International", + str_detect(ItemDescription, "Retired") & str_detect(ItemDescription, "Associate") ~ "Retired Associate", + str_detect(ItemDescription, "Retired") & str_detect(ItemDescription, "Member") ~ "Retired Member", + str_detect(ItemDescription, "Retired") & str_detect(ItemDescription, "Fellow") ~ "Retired Fellow", + str_detect(ItemDescription, "International") & str_detect(ItemDescription, "Affiliate") ~ "International Affiliate", + str_detect(ItemDescription, "International") & str_detect(ItemDescription, "Associate") ~ "International Associate", + str_detect(ItemDescription, "Upgrade to Associate") ~ "Associate", + str_detect(ItemDescription, "Upgrade to Member") ~ "Member", + str_detect(ItemDescription, "Student") ~ "Student Affiliate", + str_detect(ItemDescription, "Affiliate") ~ "Affiliate", + str_detect(ItemDescription, "Associate") ~ "Associate", + str_detect(ItemDescription, "Member") ~ "Member", + str_detect(ItemDescription, "Fellow") ~ "Fellow" ) ) %>% mutate( @@ -59,6 +36,7 @@ step_dues <- function(df, year) { case_when( Membership_Dues == "Student Affiliate" ~ 1, Membership_Dues == "Associate" ~ 2, + Membership_Dues == "Affiliate" ~ 2, Membership_Dues == "International Affiliate" ~ 3, Membership_Dues == "International Associate" ~ 3, Membership_Dues == "Member" ~ 4,