jeudi 2 mars 2017

Embedded Ifelse Statement

I have a dataset as follows:

Source     Rev_Diff    Cost_Diff     Price_Diff      Sales_Diff      
     A          -10           10             11              12
     B           11          -10            -10              11
     C          -12           10             10             -11
     D          -11          -11            -10             -12

How do I add a column where:

"If Rev_Diff is less than 0, print "Cost" if "Cost_Diff" with amount is less than 0, print "Price" if "Price_Diff" with amount is less than 0, print "Sales" if "Sales_Diff" with amount is less than 0, else print "We're up".

Final Output:

Source     Rev_Diff    Cost_Diff     Price_Diff      Sales_Diff      Reason Down     
     A          -10          -10             11              12      Cost (-10) 
     B           11          -10            -10              11      We're Up
     C          -12           10             10             -11      Sales (-11)
     D          -11          -11            -10             -12      Cost (-11), Price (-11), Sales (-12)  

Aucun commentaire:

Enregistrer un commentaire