-3

I have data with variable name as "sales enquiry date", "sales enquiry stage"

i want to create a new variable "current stage date"

so example enquirer date is 10/03/2017 and stage is Meeting, similarly, enquirer date is 27/04/2017 and stage is proposal. i want new variable, "Current stage date" <- if stage = meeting then enquirer date + 5 days i.e 15/03/2017 similarly, "current stage date" <- if stage = proposal then enquirer date + 10 days i.e 07/05/2017

1 Answers1

0

First of all, I second the commenters' recommendation for you to edit the question in line with the guidelines.

Assuming your data is in a data frame called df and the variable names are edited to not include spaces (good practice), is this what you need?

# tolower() to get around "Meeting"/"meeting"/"MEETING"...
df$current_stage_date <- if (tolower(df$sales_enquiry_stage) == "meeting") {
  df$sales_enquiry_date + 5
} else if (tolower(df$sales_enquiry_stage) == "proposal") df$sales_enquiry_date + 10

If there are only two possible values on sales_enquiry_stage (meeting and proposal), this can be further simplified to

df$current_stage_date <- df$sales_enquiry_date +
  ifelse(tolower(df$sales_enquiry_stage) == "meeting", 5, 10)
Milan Valášek
  • 571
  • 3
  • 10