Matthew Walker wrote: > Uwe Ligges wrote: >> Henrique Dallazuanna wrote: >> >>> Hi, >>> >>> Try whit: >>> >>> if(time[j] >= "18:00:00" & < "23:59:59") >>> >> >> This code is obviously wrong and does not help for the next few lines >> in the questioner's message, please do not post unsensible stuff. >> >> Uwe Ligges >> >> > > Actually, I would have said that was quite an interesting solution. If > the time is guaranteed to be in this 8 character format, then that > idea's quite easily implemented: > > # Returns true if time is between 18:00:00 and 23:59:59 > check_time <- function(time_string) { > if (nchar(time_string)!=8) stop ("Incorrect format") > time_string >= "18:00:00" & time_string <= "23:59:59" > } > > > > check_time("19:59:00") > [1] TRUE > > check_time("16:59:00") > [1] FALSE > > > > check_time("18:00:00") > [1] TRUE > > check_time("23:59:59") > [1] TRUE > > check_time("24:00:00") > [1] FALSE > > > > check_time("18:05") > Error in check_time("18:05") : Incorrect format > > > Perhaps there is an issue if the locale does not sort character-based > numbers in the same way as ASCII? But Otherwise, I can't see why this > solution wouldn't do the job. > > A more robust solution solution would parse the strings (?strptime) and > then check their days/hours/mins/seconds (?DateTimeClasses). But > perhaps the above is sufficient?
Well, the interesting part of the original question that everynody seems to omit now was the second part: if (time[j] is between 22:00:00 and 05:59:59) hence the answer is still not sufficient (even if the syntax error has been corrected) - and hence I asked for the format the time is originally in. Uwe Ligges > Cheers, > > Matthew ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.