I have a factor variable which is comprised of times. When I attempt to turn it into a factor, R orders them in order from lowest to highest. Unforunately, this means that I end up with something like the following:
1:48:55 1:53:11 1:58:18 10:04:01 10:12:45 10:14:16
10:20:24 10:21:59 10:23:11 10:23:40 10:30:40 10:34:13
10:39:47 10:54:33 10:58:43 3:21:59 3:27:38 3:37:58
3:49:00 4:20:42 4:30:52 4:37:39 4:40:08 4:40:55
4:42:25 5:03:25 5:10:30 5:10:49 5:12:39 5:14:20
So instead of printing the times in order, times with 10:00 come before 7:00.
Is there a quick way to order the times by the actual time?
time = c("1:48:55", "1:53:11", "1:58:18", "10:04:01", "10:12:45", "10:14:16", "10:20:24", "10:21:59", "10:23:11", "10:23:40", "10:30:40", "10:34:13", "10:39:47", "10:54:33", "10:58:43", "3:21:59", "3:27:38", "3:37:58", "3:49:00", "4:20:42", "4:30:52", "4:37:39", "4:40:08", "4:40:55", "4:42:25", "5:03:25", "5:10:30", "5:10:49", "5:12:39", "5:14:20")
time = factor(time)
Try this:
or this if you want the sorted vector to remain a factor: