I have some raw data that looks like this, after I exported it from R and manually added the Segment column in Excel.
Raw Data pulled into excel
I want to write code in R that will add the Segment for me.
Data description...
ID: Random distinct numbers
flag: Yes or No
Period: 0-12 Mths or 12-24 Mths
Spend Group: High, Medium or Low
Rules...
Flag = Yes
Period = 0-12 Mths
Spend Group = High
Then Segment = G01
Flag = Yes
Period = 0-12 Mths
Spend Group = Medium
Then Segment = G02
Flag = Yes
Period = 0-12 Mths
Spend Group = Low
Then Segment = G03
Flag = Yes
Period = 12-24 Mths
Spend Group = High
Then Segment = G04
...and so on until all of the variables have been accounted for
I want the code to recognise differences each time the data is processed eg, the flag won't always be Yes or No. Sometimes it will be Yes for every row.
My complete dataset summarised looks like the following image.
Summary Data
How would you start to code this in R?