-1

My data set has 2 columns, Start date and End date. I want to check if any of the rows have start date greater than the end date.

Tried below code, it failed.

Mydata$New = ifelse(Mydata$Planned.Start.Date < Mydata$Planned.Substantial.Completion.Date, 0, 1))

Error:

In Ops.factor(Mydata$Planned.Start.Date, Mydata$Planned.Substantial.Completion.Date) : ‘<’ not meaningful for factors

MLavoie
  • 9,671
  • 41
  • 36
  • 56
  • Please provide us with a reproducible example. The problem with your data is that the columns are not dates. You would have to convert them first, but we can't help on that if we don't know what the data actually look like. – Georgery Jan 27 '20 at 12:11
  • Welcome to SO! Please take a moment to read about how to post R questions: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – YOLO Jan 27 '20 at 12:31

1 Answers1

0

If your date is structured like this : Day/Month/year You can use the function dmy from the library lubridate and use it this way :

Mydata$New <- ifelse(dmy(Mydata$Planned.Start.Date) < dmy(Mydata$Planned.Substantial.Completion.Date), 0, 1))
Arkning
  • 181
  • 9