我有2個變量promo_freq和disc_freq。根據這兩個變量的值,我想創建第三個變量promo_segmnt。然而,R中嵌套的ifelse並沒有發揮作用,我得到的第三個變量的唯一值是「NA」。根據我的數據,這不能是輸出。 請找到下面提到的代碼。 在此先感謝。嵌套ifelse在R
Promotion1$promo_segmnt <-ifelse(Promotion1$disc_freq == "1.Low_disc" & Promotion1$promo_freq == "1.Low_promo","1.Low",
ifelse(Promotion1$disc_freq == "2.Med_disc" & Promotion1$promo_freq == "3.High_promo","3.High",
ifelse(Promotion1$disc_freq == "3.High_disc" & Promotion1$promo_freq == "3.High_promo","3.High ","NA")))
你能提供樣品的輸入和預期的輸出? –