[R] Help needed with aggregate or other solution

Jeff Newmiller jdnewmil at dcn.davis.ca.us
Thu Oct 26 07:28:35 CEST 2017


Thanks for the dput...

#### reproducible example of split-apply-combine ###

dta <- structure(list(date = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L,
5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L,
19L, 20L, 21L, 22L, 23L, 24L, 7L, 8L, 9L, 10L, 11L, 12L, 13L,
14L, 15L, 16L), .Label = c("2012-01-25 18:00:00", "2012-01-26 00:00:00",
"2012-01-26 06:00:00", "2012-01-26 12:00:00", "2012-01-26 18:00:00",
"2012-01-27 00:00:00", "2012-01-27 06:00:00", "2012-01-27 12:00:00",
"2012-01-27 18:00:00", "2012-01-28 00:00:00", "2012-01-28 06:00:00",
"2012-01-28 12:00:00", "2012-01-28 18:00:00", "2012-01-29 00:00:00",
"2012-01-29 06:00:00", "2012-01-29 12:00:00", "2012-01-29 18:00:00",
"2012-01-30 00:00:00", "2012-01-30 06:00:00", "2012-01-30 12:00:00",
"2012-01-30 18:00:00", "2012-01-31 00:00:00", "2012-01-31 06:00:00",
"2012-01-31 12:00:00", "2012-01-31 13:00:00", "2012-01-31 18:00:00",
"2012-02-01 00:00:00", "2012-02-01 06:00:00", "2012-02-01 12:00:00",
"2012-02-01 18:00:00", "2012-02-02 00:00:00", "2012-02-02 06:00:00",
"2012-02-02 12:00:00", "2012-02-02 18:00:00", "2012-02-03 00:00:00",
"2012-02-03 06:00:00", "2012-02-03 12:00:00", "2012-02-03 18:00:00",
"2012-02-04 00:00:00", "2012-02-04 06:00:00", "2012-02-04 12:00:00",
"2012-02-04 18:00:00", "2012-02-05 00:00:00", "2012-02-05 06:00:00",
"2012-02-05 12:00:00", "2012-02-05 18:00:00", "2012-02-06 00:00:00",
"2012-02-06 06:00:00", "2012-02-06 12:00:00", "2012-02-06 18:00:00",
"2012-02-07 00:00:00", "2012-02-07 06:00:00", "2012-02-07 12:00:00",
"2012-02-07 18:00:00", "2012-02-08 00:00:00", "2012-02-08 06:00:00",
"2012-02-08 12:00:00", "2012-02-08 18:00:00", "2012-02-09 00:00:00",
"2012-02-09 06:00:00", "2012-02-09 12:00:00", "2012-02-09 18:00:00",
"2012-02-10 00:00:00", "2012-02-10 06:00:00", "2012-02-10 12:00:00",
"2012-02-10 18:00:00", "2012-02-11 00:00:00", "2012-02-11 06:00:00",
"2012-02-11 12:00:00", "2012-02-11 18:00:00", "2012-02-12 00:00:00",
"2012-02-12 06:00:00", "2012-02-12 12:00:00", "2012-02-12 18:00:00",
"2012-02-13 00:00:00", "2012-02-13 06:00:00", "2012-02-13 12:00:00",
"2012-02-13 18:00:00", "2012-02-14 00:00:00", "2012-02-14 06:00:00",
"2012-02-14 12:00:00", "2012-02-14 18:00:00", "2012-02-15 00:00:00",
"2012-02-15 06:00:00", "2012-02-15 12:00:00", "2012-02-15 18:00:00",
"2012-02-16 00:00:00", "2012-02-16 06:00:00", "2012-02-16 12:00:00",
"2012-02-16 18:00:00", "2012-02-17 00:00:00", "2012-02-17 06:00:00",
"2012-02-17 12:00:00", "2012-02-17 18:00:00", "2012-02-18 00:00:00",
"2012-02-18 06:00:00", "2012-02-18 12:00:00", "2012-02-18 18:00:00",
"2012-02-19 00:00:00", "2012-02-19 06:00:00", "2012-02-19 12:00:00",
"2012-02-19 18:00:00", "2012-02-20 00:00:00", "2012-02-20 06:00:00",
"2012-02-20 12:00:00", "2012-02-20 18:00:00", "2012-02-21 00:00:00",
"2012-02-21 06:00:00", "2012-02-21 12:00:00", "2012-02-21 18:00:00",
"2012-02-22 00:00:00", "2012-02-22 06:00:00", "2012-02-22 12:00:00",
"2012-02-22 18:00:00", "2012-02-23 00:00:00", "2012-02-23 06:00:00",
"2012-02-23 12:00:00", "2012-02-23 18:00:00", "2012-02-24 00:00:00",
"2012-02-24 06:00:00", "2012-02-24 12:00:00", "2012-02-24 18:00:00",
"2012-02-25 00:00:00", "2012-02-25 06:00:00", "2012-02-25 12:00:00",
"2012-02-25 18:00:00", "2012-02-26 00:00:00", "2012-02-26 06:00:00",
"2012-02-26 12:00:00", "2012-02-26 18:00:00", "2012-02-27 00:00:00",
"2012-02-27 06:00:00", "2012-02-27 12:00:00", "2012-02-27 18:00:00",
"2012-02-28 00:00:00", "2012-02-28 06:00:00", "2012-02-28 12:00:00",
"2012-02-28 18:00:00", "2012-02-29 00:00:00", "2012-02-29 06:00:00",
"2012-02-29 12:00:00", "2012-02-29 18:00:00", "2012-03-01 00:00:00",
"2012-03-01 06:00:00", "2012-03-01 12:00:00", "2012-03-01 18:00:00",
"2012-03-02 00:00:00", "2012-03-02 06:00:00", "2012-03-02 12:00:00",
"2012-03-02 18:00:00", "2012-03-03 00:00:00", "2012-03-03 06:00:00",
"2012-03-03 12:00:00", "2012-03-03 18:00:00", "2012-03-04 00:00:00",
"2012-03-04 06:00:00", "2012-03-04 12:00:00", "2012-03-04 18:00:00",
"2012-03-05 00:00:00", "2012-03-05 06:00:00", "2012-03-05 12:00:00",
"2012-03-05 18:00:00", "2012-03-06 00:00:00", "2012-03-06 06:00:00",
"2012-03-06 12:00:00", "2012-03-06 18:00:00", "2012-03-07 00:00:00",
"2012-03-07 06:00:00", "2012-03-07 12:00:00", "2012-03-07 18:00:00",
"2012-03-08 00:00:00", "2012-03-08 06:00:00", "2012-03-08 12:00:00",
"2012-03-08 18:00:00", "2012-03-09 00:00:00", "2012-03-09 06:00:00",
"2012-03-09 12:00:00", "2012-03-09 18:00:00", "2012-03-10 00:00:00",
"2012-03-10 06:00:00", "2012-03-10 12:00:00", "2012-03-10 18:00:00",
"2012-03-11 00:00:00", "2012-03-11 06:00:00", "2012-03-11 12:00:00",
"2012-03-11 18:00:00", "2012-03-12 00:00:00", "2012-03-12 06:00:00",
"2012-03-12 12:00:00", "2012-03-12 18:00:00", "2012-03-13 00:00:00",
"2012-03-13 06:00:00", "2012-03-13 12:00:00", "2012-03-13 18:00:00",
"2012-03-14 00:00:00", "2012-03-14 06:00:00", "2012-03-14 12:00:00",
"2012-03-14 18:00:00", "2012-03-15 00:00:00", "2012-03-15 06:00:00",
"2012-03-15 12:00:00", "2012-03-15 18:00:00", "2012-03-16 00:00:00",
"2012-03-16 06:00:00", "2012-03-16 12:00:00", "2012-03-16 18:00:00",
"2012-03-17 00:00:00", "2012-03-17 06:00:00", "2012-03-17 12:00:00",
"2012-03-17 18:00:00", "2012-03-18 00:00:00", "2012-03-18 06:00:00",
"2012-03-18 12:00:00", "2012-03-18 18:00:00", "2012-03-19 00:00:00",
"2012-03-19 06:00:00", "2012-03-19 12:00:00", "2012-03-19 18:00:00",
"2012-03-20 00:00:00", "2012-03-20 06:00:00", "2012-03-20 12:00:00",
"2012-03-20 18:00:00", "2012-03-21 00:00:00", "2012-03-21 06:00:00",
"2012-03-21 12:00:00", "2012-03-21 18:00:00", "2012-03-22 00:00:00",
"2012-03-22 06:00:00", "2012-03-22 12:00:00", "2012-03-22 18:00:00",
"2012-03-23 00:00:00", "2012-03-23 06:00:00", "2012-03-23 12:00:00",
"2012-03-23 18:00:00", "2012-03-24 00:00:00", "2012-03-24 06:00:00",
"2012-03-24 12:00:00", "2012-03-24 18:00:00", "2012-03-25 00:00:00",
"2012-03-25 06:00:00", "2012-03-25 12:00:00", "2012-03-25 18:00:00",
"2012-03-26 00:00:00", "2012-03-26 06:00:00", "2012-03-26 12:00:00",
"2012-03-26 18:00:00", "2012-03-27 00:00:00", "2012-03-27 06:00:00",
"2012-03-27 12:00:00", "2012-03-27 18:00:00", "2012-03-28 00:00:00",
"2012-03-28 06:00:00", "2012-03-28 12:00:00", "2012-03-28 18:00:00",
"2012-03-29 00:00:00", "2012-03-29 06:00:00", "2012-03-29 12:00:00",
"2012-03-29 18:00:00", "2012-03-30 00:00:00", "2012-03-30 06:00:00",
"2012-03-30 12:00:00", "2012-03-30 18:00:00", "2012-03-31 00:00:00",
"2012-03-31 06:00:00", "2012-03-31 12:00:00", "2012-03-31 18:00:00",
"2012-04-01 00:00:00", "2012-04-01 06:00:00", "2012-04-01 12:00:00",
"2012-04-01 18:00:00", "2012-04-02 00:00:00", "2012-04-02 06:00:00",
"2012-04-02 12:00:00", "2012-04-02 18:00:00", "2012-04-03 00:00:00",
"2012-04-03 06:00:00", "2012-04-03 12:00:00", "2012-04-03 18:00:00",
"2012-04-04 00:00:00", "2012-04-04 06:00:00", "2012-04-04 12:00:00",
"2012-04-04 18:00:00", "2012-04-05 00:00:00", "2012-04-05 06:00:00",
"2012-04-05 12:00:00", "2012-04-05 18:00:00", "2012-04-06 00:00:00",
"2012-04-06 06:00:00", "2012-04-06 12:00:00", "2012-04-06 18:00:00",
"2012-04-07 00:00:00", "2012-04-07 06:00:00", "2012-04-07 12:00:00",
"2012-04-07 18:00:00", "2012-04-08 00:00:00", "2012-04-08 06:00:00",
"2012-04-08 12:00:00", "2012-04-08 18:00:00", "2012-04-09 00:00:00",
"2012-04-09 06:00:00", "2012-04-09 12:00:00", "2012-04-09 18:00:00",
"2012-04-10 00:00:00", "2012-04-10 06:00:00", "2012-04-10 12:00:00",
"2012-04-10 18:00:00", "2012-04-11 00:00:00", "2012-04-11 06:00:00",
"2012-04-11 12:00:00", "2012-04-11 18:00:00", "2012-04-12 00:00:00",
"2012-04-12 06:00:00", "2012-04-12 12:00:00", "2012-04-12 18:00:00",
"2012-04-13 00:00:00", "2012-04-13 06:00:00", "2012-04-13 12:00:00",
"2012-04-13 18:00:00", "2012-04-14 00:00:00", "2012-04-14 06:00:00",
"2012-04-14 12:00:00", "2012-04-14 18:00:00", "2012-04-15 00:00:00",
"2012-04-15 06:00:00", "2012-04-15 12:00:00", "2012-04-15 18:00:00",
"2012-04-16 00:00:00", "2012-04-16 06:00:00", "2012-04-16 12:00:00",
"2012-04-16 18:00:00", "2012-04-17 00:00:00", "2012-04-17 06:00:00",
"2012-04-17 12:00:00", "2012-04-17 18:00:00", "2012-04-18 00:00:00",
"2012-04-18 06:00:00", "2012-04-18 12:00:00", "2012-04-18 18:00:00",
"2012-04-19 00:00:00", "2012-04-19 06:00:00", "2012-04-19 12:00:00",
"2012-04-19 18:00:00", "2012-04-20 00:00:00", "2012-04-20 06:00:00",
"2012-04-20 12:00:00", "2012-04-20 18:00:00", "2012-04-21 00:00:00",
"2012-04-21 06:00:00", "2012-04-21 12:00:00", "2012-04-21 18:00:00",
"2012-04-22 00:00:00", "2012-04-22 06:00:00", "2012-04-22 12:00:00",
"2012-04-22 18:00:00", "2012-04-23 00:00:00", "2012-04-23 06:00:00",
"2012-04-23 12:00:00", "2012-04-23 18:00:00", "2012-04-24 00:00:00",
"2012-04-24 06:00:00", "2012-04-24 12:00:00", "2012-04-24 18:00:00",
"2012-04-25 00:00:00", "2012-04-25 06:00:00", "2012-04-25 12:00:00",
"2012-04-25 18:00:00", "2012-04-26 00:00:00", "2012-04-26 06:00:00",
"2012-04-26 12:00:00", "2012-04-26 18:00:00", "2012-04-27 00:00:00",
"2012-04-27 06:00:00", "2012-04-27 12:00:00", "2012-04-27 18:00:00",
"2012-04-28 00:00:00", "2012-04-28 06:00:00", "2012-04-28 12:00:00",
"2012-04-28 18:00:00", "2012-04-29 00:00:00", "2012-04-29 06:00:00",
"2012-04-29 12:00:00", "2012-04-29 18:00:00", "2012-04-30 00:00:00",
"2012-04-30 06:00:00", "2012-04-30 12:00:00", "2012-04-30 18:00:00",
"2012-05-01 00:00:00", "2012-05-01 06:00:00", "2012-05-01 12:00:00",
"2012-05-01 18:00:00", "2012-05-02 00:00:00", "2012-05-02 06:00:00",
"2012-05-02 12:00:00", "2012-05-02 18:00:00", "2012-05-03 00:00:00",
"2012-05-03 06:00:00", "2012-05-03 12:00:00", "2012-05-03 18:00:00",
"2012-05-04 00:00:00", "2012-05-04 06:00:00", "2012-05-04 12:00:00",
"2012-05-04 18:00:00", "2012-05-05 00:00:00", "2012-05-05 06:00:00",
"2012-05-05 12:00:00", "2012-05-05 18:00:00", "2012-05-06 00:00:00",
"2012-05-06 06:00:00", "2012-05-06 12:00:00", "2012-05-06 18:00:00",
"2012-05-07 00:00:00", "2012-05-07 06:00:00", "2012-05-07 12:00:00",
"2012-05-07 18:00:00", "2012-05-08 00:00:00", "2012-05-08 06:00:00",
"2012-05-08 12:00:00", "2012-05-08 18:00:00", "2012-05-09 00:00:00",
"2012-05-09 06:00:00", "2012-05-09 12:00:00", "2012-05-09 18:00:00",
"2012-05-10 00:00:00", "2012-05-10 06:00:00", "2012-05-10 12:00:00",
"2012-05-10 18:00:00", "2012-05-11 00:00:00", "2012-05-11 06:00:00",
"2012-05-11 12:00:00", "2012-05-11 18:00:00", "2012-05-12 00:00:00",
"2012-05-12 06:00:00", "2012-05-12 12:00:00", "2012-05-12 18:00:00",
"2012-05-13 00:00:00", "2012-05-13 06:00:00", "2012-05-13 12:00:00",
"2012-05-13 18:00:00", "2012-05-14 00:00:00", "2012-05-14 06:00:00",
"2012-05-14 12:00:00", "2012-05-14 18:00:00", "2012-05-15 00:00:00",
"2012-05-15 06:00:00", "2012-05-15 12:00:00", "2012-05-15 18:00:00",
"2012-05-16 00:00:00", "2012-05-16 06:00:00", "2012-05-16 12:00:00",
"2012-05-16 18:00:00", "2012-05-17 00:00:00", "2012-05-17 06:00:00",
"2012-05-17 12:00:00", "2012-05-17 18:00:00", "2012-05-18 00:00:00",
"2012-05-18 06:00:00", "2012-05-18 12:00:00", "2012-05-18 18:00:00",
"2012-05-19 00:00:00", "2012-05-19 06:00:00", "2012-05-19 12:00:00",
"2012-05-19 18:00:00", "2012-05-20 00:00:00", "2012-05-20 06:00:00",
"2012-05-20 12:00:00", "2012-05-20 18:00:00", "2012-05-21 00:00:00",
"2012-05-21 06:00:00", "2012-05-21 12:00:00", "2012-05-21 18:00:00",
"2012-05-22 00:00:00", "2012-05-22 06:00:00", "2012-05-22 12:00:00",
"2012-05-22 18:00:00", "2012-05-23 00:00:00", "2012-05-23 06:00:00",
"2012-05-23 12:00:00", "2012-05-23 18:00:00", "2012-05-24 00:00:00",
"2012-05-24 06:00:00", "2012-05-24 12:00:00", "2012-05-24 18:00:00",
"2012-05-25 00:00:00", "2012-05-25 06:00:00", "2012-05-25 12:00:00",
"2012-05-25 18:00:00", "2012-05-26 00:00:00", "2012-05-26 06:00:00",
"2012-05-26 12:00:00", "2012-05-26 18:00:00", "2012-05-27 00:00:00",
"2012-05-27 06:00:00", "2012-05-27 12:00:00", "2012-05-27 18:00:00",
"2012-05-28 00:00:00", "2012-05-28 06:00:00", "2012-05-28 12:00:00",
"2012-05-28 18:00:00", "2012-05-29 00:00:00", "2012-05-29 06:00:00",
"2012-05-29 12:00:00"), class = "factor"), basistime = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L), .Label = c("2012-01-25 15:02:00", "2012-01-26 15:11:00",
"2012-01-27 01:41:00", "2012-01-27 10:15:00", "2012-01-27 15:15:00",
"2012-01-28 14:22:00", "2012-01-29 13:33:00", "2012-01-30 14:11:00",
"2012-01-31 14:24:00", "2012-02-01 14:55:00", "2012-02-02 14:56:00",
"2012-02-03 14:40:00", "2012-02-04 15:01:00", "2012-02-05 15:04:00",
"2012-02-06 14:37:00", "2012-02-07 14:42:00", "2012-02-08 14:44:00",
"2012-02-09 14:27:00", "2012-02-10 14:33:00", "2012-02-11 15:05:00",
"2012-02-12 15:09:00", "2012-02-13 15:00:00", "2012-02-14 15:10:00",
"2012-02-15 14:46:00", "2012-02-16 14:42:00", "2012-02-17 14:14:00",
"2012-02-18 15:27:00", "2012-02-19 13:13:00", "2012-02-20 13:56:00",
"2012-02-21 14:39:00", "2012-02-22 15:33:00", "2012-02-23 15:14:00",
"2012-02-24 15:14:00", "2012-02-25 14:25:00", "2012-02-26 14:08:00",
"2012-02-27 14:55:00", "2012-02-28 14:40:00", "2012-02-29 14:45:00",
"2012-03-01 15:18:00", "2012-03-02 15:18:00", "2012-03-03 15:43:00",
"2012-03-04 15:16:00", "2012-03-05 15:17:00", "2012-03-06 15:03:00",
"2012-03-07 14:44:00", "2012-03-08 14:53:00", "2012-03-09 15:10:00",
"2012-03-10 14:43:00", "2012-03-11 13:37:00", "2012-03-12 14:58:00",
"2012-03-13 14:36:00", "2012-03-14 13:49:00", "2012-03-15 14:32:00",
"2012-03-16 15:01:00", "2012-03-17 13:55:00", "2012-03-18 13:44:00",
"2012-03-19 13:55:00", "2012-03-20 13:53:00", "2012-03-21 14:07:00",
"2012-03-22 14:03:00", "2012-03-23 14:30:00", "2012-03-24 14:47:00",
"2012-03-25 14:32:00", "2012-03-26 14:41:00", "2012-03-27 13:51:00",
"2012-03-28 13:32:00", "2012-03-29 13:59:00", "2012-03-30 14:15:00",
"2012-03-31 14:12:00", "2012-04-01 14:30:00", "2012-04-02 13:43:00",
"2012-04-03 13:54:00", "2012-04-04 13:45:00", "2012-04-05 13:46:00",
"2012-04-06 13:41:00", "2012-04-07 13:13:00", "2012-04-08 12:59:00",
"2012-04-09 13:53:00", "2012-04-10 14:15:00", "2012-04-11 14:26:00",
"2012-04-12 14:05:00", "2012-04-13 13:37:00", "2012-04-14 13:52:00",
"2012-04-15 15:00:00", "2012-04-16 14:42:00", "2012-04-17 14:21:00",
"2012-04-18 14:40:00", "2012-04-19 14:35:00", "2012-04-20 15:14:00",
"2012-04-21 14:46:00", "2012-04-22 14:44:00", "2012-04-23 14:33:00",
"2012-04-24 14:41:00", "2012-04-25 14:13:00", "2012-04-26 14:19:00",
"2012-04-27 14:35:00", "2012-04-28 13:48:00", "2012-04-29 14:12:00",
"2012-04-30 13:53:00", "2012-05-02 14:41:00", "2012-05-03 15:01:00",
"2012-05-04 15:21:00", "2012-05-05 14:57:00", "2012-05-06 14:09:00",
"2012-05-07 14:30:00", "2012-05-08 14:05:00", "2012-05-08 21:21:00",
"2012-05-09 15:02:00", "2012-05-10 14:27:00", "2012-05-11 14:47:00",
"2012-05-12 13:24:00", "2012-05-13 14:40:00", "2012-05-13 19:24:00",
"2012-05-14 14:33:00", "2012-05-15 14:39:00", "2012-05-16 14:07:00",
"2012-05-17 13:42:00", "2012-05-18 14:30:00", "2012-05-19 13:59:00",
"2012-05-20 14:14:00", "2012-05-21 14:15:00", "2012-05-22 14:18:00",
"2012-05-23 14:14:00", "2012-05-24 13:52:00"), class = "factor"),
     fcst = c(38.7, 38.9, 39.2, 39.8, 40.5, 41.5, 42.5, 43.1,
     43.9, 44.5, 44.8, 45, 45, 45.1, 45.4, 45.8, 46.4, 47, 47.5,
     47.9, 39.2, 40, 41.8, 42.2, 42.8, 44.4, 45.7, 46.2, 46.2,
     46.2, 46.5, 47, 47.5, 47.9, 48.4, 49, 49.5, 49.9, 50.2, 50.4,
     41.3, 42.5, 42.8, 42.8, 42.8, 42.9, 43, 43.3, 43.5, 43.8),
     usgs = c(38.5, 38.6, 38.6, 38.6, 39.1, 39.8, 41.2, 42.9,
     43.4, 43.6, 43.4, 43.1, 43, 43.1, 43.5, 43.8, 44.1, 44.2,
     44.4, 44.5, 39.1, 39.8, 41.2, 42.9, 43.4, 43.6, 43.4, 43.1,
     43, 43.1, 43.5, 43.8, 44.1, 44.2, 44.4, 44.5, 44.5, 44.5,
     44.6, 44.2, 41.2, 42.9, 43.4, 43.6, 43.4, 43.1, 43, 43.1,
     43.5, 43.8)), .Names = c("date", "basistime", "fcst", "usgs"
), row.names = c(NA, 50L), class = "data.frame")

Sys.setenv( "Etc/GMT+8" ) # or whatever is appropriate
#> Error in Sys.setenv("Etc/GMT+8"): all arguments must be named

dta2 <- dta
# bad idea to work with dates as factors
dta2$date <- as.POSIXct( as.character( dta2$date ) )
dta2$basistime <- as.POSIXct( as.character( dta2$basistime ) )

# base R solution

dates <- unique( dta2$date )
dta2list <- split( dta2, dta2$date )
grplist <- lapply( dta2list
                  , function( DF ) {
                      DF[ which.max( DF$fcst ), ]
                    }
                  )
result2 <- do.call( rbind, grplist )
result2
#>                                    date           basistime fcst usgs
#> 2012-01-25 18:00:00 2012-01-25 18:00:00 2012-01-25 15:02:00 38.7 38.5
#> 2012-01-26 00:00:00 2012-01-26 00:00:00 2012-01-25 15:02:00 38.9 38.6
#> 2012-01-26 06:00:00 2012-01-26 06:00:00 2012-01-25 15:02:00 39.2 38.6
#> 2012-01-26 12:00:00 2012-01-26 12:00:00 2012-01-25 15:02:00 39.8 38.6
#> 2012-01-26 18:00:00 2012-01-26 18:00:00 2012-01-25 15:02:00 40.5 39.1
#> 2012-01-27 00:00:00 2012-01-27 00:00:00 2012-01-25 15:02:00 41.5 39.8
#> 2012-01-27 06:00:00 2012-01-27 06:00:00 2012-01-25 15:02:00 42.5 41.2
#> 2012-01-27 12:00:00 2012-01-27 12:00:00 2012-01-25 15:02:00 43.1 42.9
#> 2012-01-27 18:00:00 2012-01-27 18:00:00 2012-01-25 15:02:00 43.9 43.4
#> 2012-01-28 00:00:00 2012-01-28 00:00:00 2012-01-25 15:02:00 44.5 43.6
#> 2012-01-28 06:00:00 2012-01-28 06:00:00 2012-01-26 15:11:00 45.7 43.4
#> 2012-01-28 12:00:00 2012-01-28 12:00:00 2012-01-26 15:11:00 46.2 43.1
#> 2012-01-28 18:00:00 2012-01-28 18:00:00 2012-01-26 15:11:00 46.2 43.0
#> 2012-01-29 00:00:00 2012-01-29 00:00:00 2012-01-26 15:11:00 46.2 43.1
#> 2012-01-29 06:00:00 2012-01-29 06:00:00 2012-01-26 15:11:00 46.5 43.5
#> 2012-01-29 12:00:00 2012-01-29 12:00:00 2012-01-26 15:11:00 47.0 43.8
#> 2012-01-29 18:00:00 2012-01-29 18:00:00 2012-01-26 15:11:00 47.5 44.1
#> 2012-01-30 00:00:00 2012-01-30 00:00:00 2012-01-26 15:11:00 47.9 44.2
#> 2012-01-30 06:00:00 2012-01-30 06:00:00 2012-01-26 15:11:00 48.4 44.4
#> 2012-01-30 12:00:00 2012-01-30 12:00:00 2012-01-26 15:11:00 49.0 44.5
#> 2012-01-30 18:00:00 2012-01-30 18:00:00 2012-01-26 15:11:00 49.5 44.5
#> 2012-01-31 00:00:00 2012-01-31 00:00:00 2012-01-26 15:11:00 49.9 44.5
#> 2012-01-31 06:00:00 2012-01-31 06:00:00 2012-01-26 15:11:00 50.2 44.6
#> 2012-01-31 12:00:00 2012-01-31 12:00:00 2012-01-26 15:11:00 50.4 44.2

# alternately, use tidyverse

library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#>     filter, lag
#> The following objects are masked from 'package:base':
#>
#>     intersect, setdiff, setequal, union
result3 <- (   dta2
            %>% group_by( date )
            %>% do({
                  DF <- .
                  DF[ which.max( DF$fcst ), ]
                })
            %>% ungroup
            %>% as.data.frame
            )
result3
#>                   date           basistime fcst usgs
#> 1  2012-01-25 18:00:00 2012-01-25 15:02:00 38.7 38.5
#> 2  2012-01-26 00:00:00 2012-01-25 15:02:00 38.9 38.6
#> 3  2012-01-26 06:00:00 2012-01-25 15:02:00 39.2 38.6
#> 4  2012-01-26 12:00:00 2012-01-25 15:02:00 39.8 38.6
#> 5  2012-01-26 18:00:00 2012-01-25 15:02:00 40.5 39.1
#> 6  2012-01-27 00:00:00 2012-01-25 15:02:00 41.5 39.8
#> 7  2012-01-27 06:00:00 2012-01-25 15:02:00 42.5 41.2
#> 8  2012-01-27 12:00:00 2012-01-25 15:02:00 43.1 42.9
#> 9  2012-01-27 18:00:00 2012-01-25 15:02:00 43.9 43.4
#> 10 2012-01-28 00:00:00 2012-01-25 15:02:00 44.5 43.6
#> 11 2012-01-28 06:00:00 2012-01-26 15:11:00 45.7 43.4
#> 12 2012-01-28 12:00:00 2012-01-26 15:11:00 46.2 43.1
#> 13 2012-01-28 18:00:00 2012-01-26 15:11:00 46.2 43.0
#> 14 2012-01-29 00:00:00 2012-01-26 15:11:00 46.2 43.1
#> 15 2012-01-29 06:00:00 2012-01-26 15:11:00 46.5 43.5
#> 16 2012-01-29 12:00:00 2012-01-26 15:11:00 47.0 43.8
#> 17 2012-01-29 18:00:00 2012-01-26 15:11:00 47.5 44.1
#> 18 2012-01-30 00:00:00 2012-01-26 15:11:00 47.9 44.2
#> 19 2012-01-30 06:00:00 2012-01-26 15:11:00 48.4 44.4
#> 20 2012-01-30 12:00:00 2012-01-26 15:11:00 49.0 44.5
#> 21 2012-01-30 18:00:00 2012-01-26 15:11:00 49.5 44.5
#> 22 2012-01-31 00:00:00 2012-01-26 15:11:00 49.9 44.5
#> 23 2012-01-31 06:00:00 2012-01-26 15:11:00 50.2 44.6
#> 24 2012-01-31 12:00:00 2012-01-26 15:11:00 50.4 44.2

####################################################


On Thu, 26 Oct 2017, Thomas Adams wrote:

> Hello all!
>
> I've been struggling with is for many hours today; I'm close to getting
> what I want, but not close enough...
>
> I have a dataframe consisting of two date-time columns followed by two
> numeric columns. what I need is the max value (in the first numeric column)
> based on the 2nd date-time column, which is essentially a factor. But, I
> want the result to provide both date-time values corresponding to the max
> value.
>
> My data:
>
> structure(list(date = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L,
> 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L,
> 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L,
> 19L, 20L, 21L, 22L, 23L, 24L, 7L, 8L, 9L, 10L, 11L, 12L, 13L,
> 14L, 15L, 16L), .Label = c("2012-01-25 18:00:00", "2012-01-26 00:00:00",
> "2012-01-26 06:00:00", "2012-01-26 12:00:00", "2012-01-26 18:00:00",
> "2012-01-27 00:00:00", "2012-01-27 06:00:00", "2012-01-27 12:00:00",
> "2012-01-27 18:00:00", "2012-01-28 00:00:00", "2012-01-28 06:00:00",
> "2012-01-28 12:00:00", "2012-01-28 18:00:00", "2012-01-29 00:00:00",
> "2012-01-29 06:00:00", "2012-01-29 12:00:00", "2012-01-29 18:00:00",
> "2012-01-30 00:00:00", "2012-01-30 06:00:00", "2012-01-30 12:00:00",
> "2012-01-30 18:00:00", "2012-01-31 00:00:00", "2012-01-31 06:00:00",
> "2012-01-31 12:00:00", "2012-01-31 13:00:00", "2012-01-31 18:00:00",
> "2012-02-01 00:00:00", "2012-02-01 06:00:00", "2012-02-01 12:00:00",
> "2012-02-01 18:00:00", "2012-02-02 00:00:00", "2012-02-02 06:00:00",
> "2012-02-02 12:00:00", "2012-02-02 18:00:00", "2012-02-03 00:00:00",
> "2012-02-03 06:00:00", "2012-02-03 12:00:00", "2012-02-03 18:00:00",
> "2012-02-04 00:00:00", "2012-02-04 06:00:00", "2012-02-04 12:00:00",
> "2012-02-04 18:00:00", "2012-02-05 00:00:00", "2012-02-05 06:00:00",
> "2012-02-05 12:00:00", "2012-02-05 18:00:00", "2012-02-06 00:00:00",
> "2012-02-06 06:00:00", "2012-02-06 12:00:00", "2012-02-06 18:00:00",
> "2012-02-07 00:00:00", "2012-02-07 06:00:00", "2012-02-07 12:00:00",
> "2012-02-07 18:00:00", "2012-02-08 00:00:00", "2012-02-08 06:00:00",
> "2012-02-08 12:00:00", "2012-02-08 18:00:00", "2012-02-09 00:00:00",
> "2012-02-09 06:00:00", "2012-02-09 12:00:00", "2012-02-09 18:00:00",
> "2012-02-10 00:00:00", "2012-02-10 06:00:00", "2012-02-10 12:00:00",
> "2012-02-10 18:00:00", "2012-02-11 00:00:00", "2012-02-11 06:00:00",
> "2012-02-11 12:00:00", "2012-02-11 18:00:00", "2012-02-12 00:00:00",
> "2012-02-12 06:00:00", "2012-02-12 12:00:00", "2012-02-12 18:00:00",
> "2012-02-13 00:00:00", "2012-02-13 06:00:00", "2012-02-13 12:00:00",
> "2012-02-13 18:00:00", "2012-02-14 00:00:00", "2012-02-14 06:00:00",
> "2012-02-14 12:00:00", "2012-02-14 18:00:00", "2012-02-15 00:00:00",
> "2012-02-15 06:00:00", "2012-02-15 12:00:00", "2012-02-15 18:00:00",
> "2012-02-16 00:00:00", "2012-02-16 06:00:00", "2012-02-16 12:00:00",
> "2012-02-16 18:00:00", "2012-02-17 00:00:00", "2012-02-17 06:00:00",
> "2012-02-17 12:00:00", "2012-02-17 18:00:00", "2012-02-18 00:00:00",
> "2012-02-18 06:00:00", "2012-02-18 12:00:00", "2012-02-18 18:00:00",
> "2012-02-19 00:00:00", "2012-02-19 06:00:00", "2012-02-19 12:00:00",
> "2012-02-19 18:00:00", "2012-02-20 00:00:00", "2012-02-20 06:00:00",
> "2012-02-20 12:00:00", "2012-02-20 18:00:00", "2012-02-21 00:00:00",
> "2012-02-21 06:00:00", "2012-02-21 12:00:00", "2012-02-21 18:00:00",
> "2012-02-22 00:00:00", "2012-02-22 06:00:00", "2012-02-22 12:00:00",
> "2012-02-22 18:00:00", "2012-02-23 00:00:00", "2012-02-23 06:00:00",
> "2012-02-23 12:00:00", "2012-02-23 18:00:00", "2012-02-24 00:00:00",
> "2012-02-24 06:00:00", "2012-02-24 12:00:00", "2012-02-24 18:00:00",
> "2012-02-25 00:00:00", "2012-02-25 06:00:00", "2012-02-25 12:00:00",
> "2012-02-25 18:00:00", "2012-02-26 00:00:00", "2012-02-26 06:00:00",
> "2012-02-26 12:00:00", "2012-02-26 18:00:00", "2012-02-27 00:00:00",
> "2012-02-27 06:00:00", "2012-02-27 12:00:00", "2012-02-27 18:00:00",
> "2012-02-28 00:00:00", "2012-02-28 06:00:00", "2012-02-28 12:00:00",
> "2012-02-28 18:00:00", "2012-02-29 00:00:00", "2012-02-29 06:00:00",
> "2012-02-29 12:00:00", "2012-02-29 18:00:00", "2012-03-01 00:00:00",
> "2012-03-01 06:00:00", "2012-03-01 12:00:00", "2012-03-01 18:00:00",
> "2012-03-02 00:00:00", "2012-03-02 06:00:00", "2012-03-02 12:00:00",
> "2012-03-02 18:00:00", "2012-03-03 00:00:00", "2012-03-03 06:00:00",
> "2012-03-03 12:00:00", "2012-03-03 18:00:00", "2012-03-04 00:00:00",
> "2012-03-04 06:00:00", "2012-03-04 12:00:00", "2012-03-04 18:00:00",
> "2012-03-05 00:00:00", "2012-03-05 06:00:00", "2012-03-05 12:00:00",
> "2012-03-05 18:00:00", "2012-03-06 00:00:00", "2012-03-06 06:00:00",
> "2012-03-06 12:00:00", "2012-03-06 18:00:00", "2012-03-07 00:00:00",
> "2012-03-07 06:00:00", "2012-03-07 12:00:00", "2012-03-07 18:00:00",
> "2012-03-08 00:00:00", "2012-03-08 06:00:00", "2012-03-08 12:00:00",
> "2012-03-08 18:00:00", "2012-03-09 00:00:00", "2012-03-09 06:00:00",
> "2012-03-09 12:00:00", "2012-03-09 18:00:00", "2012-03-10 00:00:00",
> "2012-03-10 06:00:00", "2012-03-10 12:00:00", "2012-03-10 18:00:00",
> "2012-03-11 00:00:00", "2012-03-11 06:00:00", "2012-03-11 12:00:00",
> "2012-03-11 18:00:00", "2012-03-12 00:00:00", "2012-03-12 06:00:00",
> "2012-03-12 12:00:00", "2012-03-12 18:00:00", "2012-03-13 00:00:00",
> "2012-03-13 06:00:00", "2012-03-13 12:00:00", "2012-03-13 18:00:00",
> "2012-03-14 00:00:00", "2012-03-14 06:00:00", "2012-03-14 12:00:00",
> "2012-03-14 18:00:00", "2012-03-15 00:00:00", "2012-03-15 06:00:00",
> "2012-03-15 12:00:00", "2012-03-15 18:00:00", "2012-03-16 00:00:00",
> "2012-03-16 06:00:00", "2012-03-16 12:00:00", "2012-03-16 18:00:00",
> "2012-03-17 00:00:00", "2012-03-17 06:00:00", "2012-03-17 12:00:00",
> "2012-03-17 18:00:00", "2012-03-18 00:00:00", "2012-03-18 06:00:00",
> "2012-03-18 12:00:00", "2012-03-18 18:00:00", "2012-03-19 00:00:00",
> "2012-03-19 06:00:00", "2012-03-19 12:00:00", "2012-03-19 18:00:00",
> "2012-03-20 00:00:00", "2012-03-20 06:00:00", "2012-03-20 12:00:00",
> "2012-03-20 18:00:00", "2012-03-21 00:00:00", "2012-03-21 06:00:00",
> "2012-03-21 12:00:00", "2012-03-21 18:00:00", "2012-03-22 00:00:00",
> "2012-03-22 06:00:00", "2012-03-22 12:00:00", "2012-03-22 18:00:00",
> "2012-03-23 00:00:00", "2012-03-23 06:00:00", "2012-03-23 12:00:00",
> "2012-03-23 18:00:00", "2012-03-24 00:00:00", "2012-03-24 06:00:00",
> "2012-03-24 12:00:00", "2012-03-24 18:00:00", "2012-03-25 00:00:00",
> "2012-03-25 06:00:00", "2012-03-25 12:00:00", "2012-03-25 18:00:00",
> "2012-03-26 00:00:00", "2012-03-26 06:00:00", "2012-03-26 12:00:00",
> "2012-03-26 18:00:00", "2012-03-27 00:00:00", "2012-03-27 06:00:00",
> "2012-03-27 12:00:00", "2012-03-27 18:00:00", "2012-03-28 00:00:00",
> "2012-03-28 06:00:00", "2012-03-28 12:00:00", "2012-03-28 18:00:00",
> "2012-03-29 00:00:00", "2012-03-29 06:00:00", "2012-03-29 12:00:00",
> "2012-03-29 18:00:00", "2012-03-30 00:00:00", "2012-03-30 06:00:00",
> "2012-03-30 12:00:00", "2012-03-30 18:00:00", "2012-03-31 00:00:00",
> "2012-03-31 06:00:00", "2012-03-31 12:00:00", "2012-03-31 18:00:00",
> "2012-04-01 00:00:00", "2012-04-01 06:00:00", "2012-04-01 12:00:00",
> "2012-04-01 18:00:00", "2012-04-02 00:00:00", "2012-04-02 06:00:00",
> "2012-04-02 12:00:00", "2012-04-02 18:00:00", "2012-04-03 00:00:00",
> "2012-04-03 06:00:00", "2012-04-03 12:00:00", "2012-04-03 18:00:00",
> "2012-04-04 00:00:00", "2012-04-04 06:00:00", "2012-04-04 12:00:00",
> "2012-04-04 18:00:00", "2012-04-05 00:00:00", "2012-04-05 06:00:00",
> "2012-04-05 12:00:00", "2012-04-05 18:00:00", "2012-04-06 00:00:00",
> "2012-04-06 06:00:00", "2012-04-06 12:00:00", "2012-04-06 18:00:00",
> "2012-04-07 00:00:00", "2012-04-07 06:00:00", "2012-04-07 12:00:00",
> "2012-04-07 18:00:00", "2012-04-08 00:00:00", "2012-04-08 06:00:00",
> "2012-04-08 12:00:00", "2012-04-08 18:00:00", "2012-04-09 00:00:00",
> "2012-04-09 06:00:00", "2012-04-09 12:00:00", "2012-04-09 18:00:00",
> "2012-04-10 00:00:00", "2012-04-10 06:00:00", "2012-04-10 12:00:00",
> "2012-04-10 18:00:00", "2012-04-11 00:00:00", "2012-04-11 06:00:00",
> "2012-04-11 12:00:00", "2012-04-11 18:00:00", "2012-04-12 00:00:00",
> "2012-04-12 06:00:00", "2012-04-12 12:00:00", "2012-04-12 18:00:00",
> "2012-04-13 00:00:00", "2012-04-13 06:00:00", "2012-04-13 12:00:00",
> "2012-04-13 18:00:00", "2012-04-14 00:00:00", "2012-04-14 06:00:00",
> "2012-04-14 12:00:00", "2012-04-14 18:00:00", "2012-04-15 00:00:00",
> "2012-04-15 06:00:00", "2012-04-15 12:00:00", "2012-04-15 18:00:00",
> "2012-04-16 00:00:00", "2012-04-16 06:00:00", "2012-04-16 12:00:00",
> "2012-04-16 18:00:00", "2012-04-17 00:00:00", "2012-04-17 06:00:00",
> "2012-04-17 12:00:00", "2012-04-17 18:00:00", "2012-04-18 00:00:00",
> "2012-04-18 06:00:00", "2012-04-18 12:00:00", "2012-04-18 18:00:00",
> "2012-04-19 00:00:00", "2012-04-19 06:00:00", "2012-04-19 12:00:00",
> "2012-04-19 18:00:00", "2012-04-20 00:00:00", "2012-04-20 06:00:00",
> "2012-04-20 12:00:00", "2012-04-20 18:00:00", "2012-04-21 00:00:00",
> "2012-04-21 06:00:00", "2012-04-21 12:00:00", "2012-04-21 18:00:00",
> "2012-04-22 00:00:00", "2012-04-22 06:00:00", "2012-04-22 12:00:00",
> "2012-04-22 18:00:00", "2012-04-23 00:00:00", "2012-04-23 06:00:00",
> "2012-04-23 12:00:00", "2012-04-23 18:00:00", "2012-04-24 00:00:00",
> "2012-04-24 06:00:00", "2012-04-24 12:00:00", "2012-04-24 18:00:00",
> "2012-04-25 00:00:00", "2012-04-25 06:00:00", "2012-04-25 12:00:00",
> "2012-04-25 18:00:00", "2012-04-26 00:00:00", "2012-04-26 06:00:00",
> "2012-04-26 12:00:00", "2012-04-26 18:00:00", "2012-04-27 00:00:00",
> "2012-04-27 06:00:00", "2012-04-27 12:00:00", "2012-04-27 18:00:00",
> "2012-04-28 00:00:00", "2012-04-28 06:00:00", "2012-04-28 12:00:00",
> "2012-04-28 18:00:00", "2012-04-29 00:00:00", "2012-04-29 06:00:00",
> "2012-04-29 12:00:00", "2012-04-29 18:00:00", "2012-04-30 00:00:00",
> "2012-04-30 06:00:00", "2012-04-30 12:00:00", "2012-04-30 18:00:00",
> "2012-05-01 00:00:00", "2012-05-01 06:00:00", "2012-05-01 12:00:00",
> "2012-05-01 18:00:00", "2012-05-02 00:00:00", "2012-05-02 06:00:00",
> "2012-05-02 12:00:00", "2012-05-02 18:00:00", "2012-05-03 00:00:00",
> "2012-05-03 06:00:00", "2012-05-03 12:00:00", "2012-05-03 18:00:00",
> "2012-05-04 00:00:00", "2012-05-04 06:00:00", "2012-05-04 12:00:00",
> "2012-05-04 18:00:00", "2012-05-05 00:00:00", "2012-05-05 06:00:00",
> "2012-05-05 12:00:00", "2012-05-05 18:00:00", "2012-05-06 00:00:00",
> "2012-05-06 06:00:00", "2012-05-06 12:00:00", "2012-05-06 18:00:00",
> "2012-05-07 00:00:00", "2012-05-07 06:00:00", "2012-05-07 12:00:00",
> "2012-05-07 18:00:00", "2012-05-08 00:00:00", "2012-05-08 06:00:00",
> "2012-05-08 12:00:00", "2012-05-08 18:00:00", "2012-05-09 00:00:00",
> "2012-05-09 06:00:00", "2012-05-09 12:00:00", "2012-05-09 18:00:00",
> "2012-05-10 00:00:00", "2012-05-10 06:00:00", "2012-05-10 12:00:00",
> "2012-05-10 18:00:00", "2012-05-11 00:00:00", "2012-05-11 06:00:00",
> "2012-05-11 12:00:00", "2012-05-11 18:00:00", "2012-05-12 00:00:00",
> "2012-05-12 06:00:00", "2012-05-12 12:00:00", "2012-05-12 18:00:00",
> "2012-05-13 00:00:00", "2012-05-13 06:00:00", "2012-05-13 12:00:00",
> "2012-05-13 18:00:00", "2012-05-14 00:00:00", "2012-05-14 06:00:00",
> "2012-05-14 12:00:00", "2012-05-14 18:00:00", "2012-05-15 00:00:00",
> "2012-05-15 06:00:00", "2012-05-15 12:00:00", "2012-05-15 18:00:00",
> "2012-05-16 00:00:00", "2012-05-16 06:00:00", "2012-05-16 12:00:00",
> "2012-05-16 18:00:00", "2012-05-17 00:00:00", "2012-05-17 06:00:00",
> "2012-05-17 12:00:00", "2012-05-17 18:00:00", "2012-05-18 00:00:00",
> "2012-05-18 06:00:00", "2012-05-18 12:00:00", "2012-05-18 18:00:00",
> "2012-05-19 00:00:00", "2012-05-19 06:00:00", "2012-05-19 12:00:00",
> "2012-05-19 18:00:00", "2012-05-20 00:00:00", "2012-05-20 06:00:00",
> "2012-05-20 12:00:00", "2012-05-20 18:00:00", "2012-05-21 00:00:00",
> "2012-05-21 06:00:00", "2012-05-21 12:00:00", "2012-05-21 18:00:00",
> "2012-05-22 00:00:00", "2012-05-22 06:00:00", "2012-05-22 12:00:00",
> "2012-05-22 18:00:00", "2012-05-23 00:00:00", "2012-05-23 06:00:00",
> "2012-05-23 12:00:00", "2012-05-23 18:00:00", "2012-05-24 00:00:00",
> "2012-05-24 06:00:00", "2012-05-24 12:00:00", "2012-05-24 18:00:00",
> "2012-05-25 00:00:00", "2012-05-25 06:00:00", "2012-05-25 12:00:00",
> "2012-05-25 18:00:00", "2012-05-26 00:00:00", "2012-05-26 06:00:00",
> "2012-05-26 12:00:00", "2012-05-26 18:00:00", "2012-05-27 00:00:00",
> "2012-05-27 06:00:00", "2012-05-27 12:00:00", "2012-05-27 18:00:00",
> "2012-05-28 00:00:00", "2012-05-28 06:00:00", "2012-05-28 12:00:00",
> "2012-05-28 18:00:00", "2012-05-29 00:00:00", "2012-05-29 06:00:00",
> "2012-05-29 12:00:00"), class = "factor"), basistime = structure(c(1L,
> 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
> 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
> 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
> 3L), .Label = c("2012-01-25 15:02:00", "2012-01-26 15:11:00",
> "2012-01-27 01:41:00", "2012-01-27 10:15:00", "2012-01-27 15:15:00",
> "2012-01-28 14:22:00", "2012-01-29 13:33:00", "2012-01-30 14:11:00",
> "2012-01-31 14:24:00", "2012-02-01 14:55:00", "2012-02-02 14:56:00",
> "2012-02-03 14:40:00", "2012-02-04 15:01:00", "2012-02-05 15:04:00",
> "2012-02-06 14:37:00", "2012-02-07 14:42:00", "2012-02-08 14:44:00",
> "2012-02-09 14:27:00", "2012-02-10 14:33:00", "2012-02-11 15:05:00",
> "2012-02-12 15:09:00", "2012-02-13 15:00:00", "2012-02-14 15:10:00",
> "2012-02-15 14:46:00", "2012-02-16 14:42:00", "2012-02-17 14:14:00",
> "2012-02-18 15:27:00", "2012-02-19 13:13:00", "2012-02-20 13:56:00",
> "2012-02-21 14:39:00", "2012-02-22 15:33:00", "2012-02-23 15:14:00",
> "2012-02-24 15:14:00", "2012-02-25 14:25:00", "2012-02-26 14:08:00",
> "2012-02-27 14:55:00", "2012-02-28 14:40:00", "2012-02-29 14:45:00",
> "2012-03-01 15:18:00", "2012-03-02 15:18:00", "2012-03-03 15:43:00",
> "2012-03-04 15:16:00", "2012-03-05 15:17:00", "2012-03-06 15:03:00",
> "2012-03-07 14:44:00", "2012-03-08 14:53:00", "2012-03-09 15:10:00",
> "2012-03-10 14:43:00", "2012-03-11 13:37:00", "2012-03-12 14:58:00",
> "2012-03-13 14:36:00", "2012-03-14 13:49:00", "2012-03-15 14:32:00",
> "2012-03-16 15:01:00", "2012-03-17 13:55:00", "2012-03-18 13:44:00",
> "2012-03-19 13:55:00", "2012-03-20 13:53:00", "2012-03-21 14:07:00",
> "2012-03-22 14:03:00", "2012-03-23 14:30:00", "2012-03-24 14:47:00",
> "2012-03-25 14:32:00", "2012-03-26 14:41:00", "2012-03-27 13:51:00",
> "2012-03-28 13:32:00", "2012-03-29 13:59:00", "2012-03-30 14:15:00",
> "2012-03-31 14:12:00", "2012-04-01 14:30:00", "2012-04-02 13:43:00",
> "2012-04-03 13:54:00", "2012-04-04 13:45:00", "2012-04-05 13:46:00",
> "2012-04-06 13:41:00", "2012-04-07 13:13:00", "2012-04-08 12:59:00",
> "2012-04-09 13:53:00", "2012-04-10 14:15:00", "2012-04-11 14:26:00",
> "2012-04-12 14:05:00", "2012-04-13 13:37:00", "2012-04-14 13:52:00",
> "2012-04-15 15:00:00", "2012-04-16 14:42:00", "2012-04-17 14:21:00",
> "2012-04-18 14:40:00", "2012-04-19 14:35:00", "2012-04-20 15:14:00",
> "2012-04-21 14:46:00", "2012-04-22 14:44:00", "2012-04-23 14:33:00",
> "2012-04-24 14:41:00", "2012-04-25 14:13:00", "2012-04-26 14:19:00",
> "2012-04-27 14:35:00", "2012-04-28 13:48:00", "2012-04-29 14:12:00",
> "2012-04-30 13:53:00", "2012-05-02 14:41:00", "2012-05-03 15:01:00",
> "2012-05-04 15:21:00", "2012-05-05 14:57:00", "2012-05-06 14:09:00",
> "2012-05-07 14:30:00", "2012-05-08 14:05:00", "2012-05-08 21:21:00",
> "2012-05-09 15:02:00", "2012-05-10 14:27:00", "2012-05-11 14:47:00",
> "2012-05-12 13:24:00", "2012-05-13 14:40:00", "2012-05-13 19:24:00",
> "2012-05-14 14:33:00", "2012-05-15 14:39:00", "2012-05-16 14:07:00",
> "2012-05-17 13:42:00", "2012-05-18 14:30:00", "2012-05-19 13:59:00",
> "2012-05-20 14:14:00", "2012-05-21 14:15:00", "2012-05-22 14:18:00",
> "2012-05-23 14:14:00", "2012-05-24 13:52:00"), class = "factor"),
>    fcst = c(38.7, 38.9, 39.2, 39.8, 40.5, 41.5, 42.5, 43.1,
>    43.9, 44.5, 44.8, 45, 45, 45.1, 45.4, 45.8, 46.4, 47, 47.5,
>    47.9, 39.2, 40, 41.8, 42.2, 42.8, 44.4, 45.7, 46.2, 46.2,
>    46.2, 46.5, 47, 47.5, 47.9, 48.4, 49, 49.5, 49.9, 50.2, 50.4,
>    41.3, 42.5, 42.8, 42.8, 42.8, 42.9, 43, 43.3, 43.5, 43.8),
>    usgs = c(38.5, 38.6, 38.6, 38.6, 39.1, 39.8, 41.2, 42.9,
>    43.4, 43.6, 43.4, 43.1, 43, 43.1, 43.5, 43.8, 44.1, 44.2,
>    44.4, 44.5, 39.1, 39.8, 41.2, 42.9, 43.4, 43.6, 43.4, 43.1,
>    43, 43.1, 43.5, 43.8, 44.1, 44.2, 44.4, 44.5, 44.5, 44.5,
>    44.6, 44.2, 41.2, 42.9, 43.4, 43.6, 43.4, 43.1, 43, 43.1,
>    43.5, 43.8)), .Names = c("date", "basistime", "fcst", "usgs"
> ), row.names = c(NA, 50L), class = "data.frame")
>
> aggregate(fcst ~ basistime,data=legacy, FUN= max)
>
> A snippet...
>
>              basistime fcst
> 1   2012-01-25 15:02:00 47.9
> 2   2012-01-26 15:11:00 50.4
> 3   2012-01-27 01:41:00 46.0
> 4   2012-01-27 10:15:00 47.3
> 5   2012-01-27 15:15:00 47.3
> 6   2012-01-28 14:22:00 46.2
> 7   2012-01-29 13:33:00 45.8
> 8   2012-01-30 14:11:00 44.8
> 9   2012-01-31 14:24:00 43.9
> 10  2012-02-01 14:55:00 41.1
> 11  2012-02-02 14:56:00 38.1
> 12  2012-02-03 14:40:00 36.2
> 13  2012-02-04 15:01:00 34.7
> 14  2012-02-05 15:04:00 33.1
> 15  2012-02-06 14:37:00 32.2
>
> This is what I want, except I need the other corresponding date-time column
> as well. I've tried this with the date-times as factors and as POSIXct
> values and using many of the combinations suggested in the documentation
> and other examples. The closest I can get returns the second date as a
> numeric value:
>
> aggregate(cbind(fcst,date) ~ basistime,data=legacy, FUN= max)
>
> Produces:
>
>              basistime fcst       date
> 1   2012-01-25 15:02:00 47.9 1327942800
> 2   2012-01-26 15:11:00 50.4 1328029200
> 3   2012-01-27 01:41:00 46.0 1328072400
> 4   2012-01-27 10:15:00 47.3 1328032800
> 5   2012-01-27 15:15:00 47.3 1328115600
> 6   2012-01-28 14:22:00 46.2 1328202000
> 7   2012-01-29 13:33:00 45.8 1328288400
> 8   2012-01-30 14:11:00 44.8 1328374800
> 9   2012-01-31 14:24:00 43.9 1328461200
> 10  2012-02-01 14:55:00 41.1 1328547600
> 11  2012-02-02 14:56:00 38.1 1328634000
> 12  2012-02-03 14:40:00 36.2 1328720400
> 13  2012-02-04 15:01:00 34.7 1328806800
> 14  2012-02-05 15:04:00 33.1 1328893200
> 15  2012-02-06 14:37:00 32.2 1328979600
> 16  2012-02-07 14:42:00 31.2 1329066000
> 17  2012-02-08 14:44:00 30.4 1329152400
> 18  2012-02-09 14:27:00 30.0 1329238800
>
>
> Help is greatly appreciated!
>
> Regards,
> Tom
>
> --
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                       Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k



More information about the R-help mailing list