Hi, I am new to R programming and I just try to write simple If else statement in R but it is throwing me the below error and also warning message. I would like to know why this error as well as warning coming up. Can someone help me out please.
Error in if (Medication == "Medication Prior to Start of Visit" | Medication == :
missing value where TRUE/FALSE needed
In addition: Warning message:
In if (Medication == "Medication Prior to Start of Visit" | Medication == :
the condition has length > 1 and only the first element will be used
My code is given below:
searching_studyCM <- function(Start_date, End_Date, Medication) {
if(Medication == "Medication Prior to Start of Visit" | Medication == "Medication after start of Visit")
{
No_days <- End_Date - Start_date
} else if (is.na(Medication)) {
No_days <- -1
} else {
No_days <- -1
}
return(No_days)
}