is_established_customerF <- function(customer_segment, credits_purchased) { print(typeof(customer_segment)) # prints only once? established_customer_threshold <- 100000000 # infinitely large customer_segment <- as.character(customer_segment) if (customer_segment == "multiple_photographer_company") { established_customer_threshold <- 3000 } else if (customer_segment == "in_house_photography_department") { established_customer_threshold <- 1000 } else if (customer_segment == "full_time_single_re_photographer") { established_customer_threshold <- 1000 } else if (customer_segment == "part_time_single_re_photographer") { print("matched PT") established_customer_threshold <- 350 } else if (customer_segment == "real_estate_agent") { print("matched RE") established_customer_threshold <- 150 } # prints N times? print(paste(customer_segment, credits_purchased, ">", established_customer_threshold, credits_purchased > established_customer_threshold)) return(credits_purchased > established_customer_threshold) } data[1:50][is_established_customerF(customer_segment, tx_cum_amount) == TRUE] ### output ### expect the `established_customer_threshold` to be different for these rows... [20] "real_estate_agent 300 > 150 TRUE" [21] "full_time_single_re_photographer NA > 150 NA"