-2

My issue is I'm trying to see if TimeA comes before TimeB so I am doing

ifelse(timeA < timeb, 0, 1)

I get:

1: In Ops.factor(TimeA, TimeB) : < not meaningful for factors.

So how do I convert my time format so that it isn't a factor? My current time format is hh:mm:ss?

thelatemail
  • 91,185
  • 12
  • 128
  • 188
Junior R
  • 93
  • 2
  • 12
  • 1
    In what context? You absolutely can, but in so many ways that you're unlikely to get a useful answer without making your question more specific. I suspect `ifelse` may help, though. – sebastian-c Aug 12 '13 at 01:02
  • Please go through the earlier post [here](http://stackoverflow.com/questions/15164759/using-ifelse-with-transform-in-ddply) – Metrics Aug 12 '13 at 01:12
  • Your time variable is in hour minutes (from your earlier post), so you need to format that before using `ifelse`. You can provide the sample example along with the code, but please don't repeat the same question again and again. – Metrics Aug 12 '13 at 01:17
  • Please post the result of `dput(head(timeA))` and `dput(head(timeB))`. – Ferdinand.kraft Aug 12 '13 at 18:29

1 Answers1

2

Your answer sounds like it is right there in the error message:

1: In Ops.factor(TimeA, TimeB) : < not meaningful for factors.

factors don't have an explicit numeric value for comparison's sake. Consider:

factor("chicken") < factor("beef")
#[1] NA
#Warning message:
#In Ops.factor(factor("chicken"), factor("beef")) :
#  < not meaningful for factors

You're comparing things which aren't mathematically comparable (though chicken is clearly the tastier meat if you ask me). If you are comparing unformatted time values as @Metrics suggests, you are essentially repeating the same problem as above.

factor("09:05:10") < factor("09:05:20")
#[1] NA
#Warning message:
#In Ops.factor(factor("09:05:10"), factor("09:05:20")) :
#  < not meaningful for factors

But if you specify the values formally as date/time values, which are essentially numeric values, then you are sweet:

as.POSIXct("09:05:10",format="%H:%M:%S") < as.POSIXct("09:05:20","%H:%M:%S")

Just remember, unless you can represent your data sensible/meaningfully in a numeric form, then you can't sensible/meaningfully check if one value is larger or smaller than another.

thelatemail
  • 91,185
  • 12
  • 128
  • 188