mardi 7 mai 2019

how to get next month or current month based on conditionals in R

I have the below data , from which I need to create a calculated field - Change_Month.

The psuedo code for Change_Month is: if change_dt is less than 15th of the Month, Change_Month is the same month , else it is the next month.

Adv_Code    Change_Dt     
A201        12/04/2017
A198        27/07/2017    
S1212       10/11/2017  

I have tried doing:

df = mutate(df,
                Change_Month = months(Change_Dt,abbreviate = FALSE))

Note : Change_Dt is character datatype.

Expected output:
Adv_Code    Change_Dt   Change_Month     
A201        12/04/2017      April
A198        27/07/2017      August
S1212       10/11/2017      November

Can someone please help me with ifelse within the mutate statement to get the desired output?

Aucun commentaire:

Enregistrer un commentaire