I have 5 columns:
- col1 is Account Number
- col2 is Product Type
- Col3 is Date Borrowed
- Col4 is Date Returned
- Col5 is Most Recent Months End
If Col4, Date Returned, is blank meaning the product hasnt been returned then it shows up as NA.
What I would like to do, if the product hasn't been returned, meaning Col4 is NA, then I would like to replace it with the date in Col5 (most recent month end). I have tried using an ifelse statement, but when i do, it converts the dates to a numeric. The data I use is being pulled into R from a SQL Query, so that may be where the problem is arising. My code is below:
Query2<-data.frame(q2)
Query2$BorrowDate<-as.yearmon(Query2$BorrowDate)
Query2$ReturnDate<-as.yearmon(Query2$ReturnDate)
Query2$MonthEnd<-as.yearmon(Query2$MonthEnd)
Query2$Returned<-ifelse(is.na(Query2$ReturnDate),Query2$MonthEnd,Query2$ReturnDate)
BorrowD<-mondate(Query2$BorrowDate)
ReturnD<-mondate(Query2$ReturnDate)
Query2$MonthDiff<-Round(MonthsBetween(BorrowD,ReturnD),digits=0)
Thanks for your help