Re: [R] Help needed with aggregate or other solution
Hi Thomas, Would this work: res1=aggregate(dta[,"fcst"],by=list(basistime=dta[,"basistime"]),FUN=max) mm=match(paste(res1[,"basistime"],res1[,"x"]),paste(dta[,"basistime"],dta[,"fcst"])) dta[mm,] > dta[mm,] date basistime fcst usgs 20 2012-01-30 12:00:00 2012-01-25 15:02:00 47.9 44.5 40 2012-01-31 12:00:00 2012-01-26 15:11:00 50.4 44.2 50 2012-01-29 12:00:00 2012-01-27 01:41:00 43.8 43.8 cheers Peter > On 26. Oct 2017, at 17:07, Jeff Newmillerwrote: > > On Thu, 26 Oct 2017, Thomas Adams wrote: > >> Hi Jeff, >> Thank you for the suggestions -- I appreciate your help. Unfortunately, the >> result2 has two problems... >> (1) there are now 3 date columns (it looks like 2 cols are merged into 1 >> col) > > No, there are two date columns. Result2 includes the grouping value as a row > name (pulled from the names of the dta2list items by rbind). > >> (2) the output rows should not have any of the basistime dates repeated >> (maybe I misstated the problem); I need the max fcst value by basistime, but >> also list the date value for that row; for example: > > Then try out my code replacing > > dta2list <- split( dta2, dta2$date ) > > with > > dta2list <- split( dta2, dta2$basistime ) > > and > > %>% group_by( date ) > > with > > %>% group_by( basistime ) > > Please study how the code works and ask questions based on gaps in that > knowledge rather than how the results are not what you expected. This mailing > list is not a do-your-work-for-you coding service. Some help pages you should > look at include: > > ?rownames > ?split > ?lapply > ?do.call > ?rbind > ?group_by > ?do > > You might also find [1] helpful in general, and [2] helpful for understanding > dplyr. > > [1] H. Wickham, The Split-Apply-Combine Strategy for Data Analysis, Journal > of Statistical Software, vol. 40, no. 1, Apr. 2011. > > [2] H. Wickham and G. Grolemund, R for Data Science. OReilly UK Ltd, 2017. > URL: https://r4ds.had.co.nz. > >> 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 very close to what I need. The basistime dates are all unique, with >> the max fcst value for the available basistime dates; but I additionally >> need the corresponding 'date' value. >> Best, >> Tom >> On Thu, Oct 26, 2017 at 1:28 AM, Jeff Newmiller >> wrote: >> 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 >>
Re: [R] Help needed with aggregate or other solution
On 10/26/2017 4:58 AM, Thomas Adams wrote: Hi Jeff, Thank you for the suggestions -- I appreciate your help. Unfortunately, the result2 has two problems... (1) there are now 3 date columns (it looks like 2 cols are merged into 1 col) (2) the output rows should not have any of the basistime dates repeated (maybe I misstated the problem); I need the max fcst value by basistime, but also list the date value for that row; for example: 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 very close to what I need. The basistime dates are all unique, with the max fcst value for the available basistime dates; but I additionally need the corresponding 'date' value. Best, Tom On Thu, Oct 26, 2017 at 1:28 AM, Jeff Newmillerwrote: 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
Re: [R] Help needed with aggregate or other solution
On Thu, 26 Oct 2017, Thomas Adams wrote: Hi Jeff, Thank you for the suggestions -- I appreciate your help. Unfortunately, the result2 has two problems... (1) there are now 3 date columns (it looks like 2 cols are merged into 1 col) No, there are two date columns. Result2 includes the grouping value as a row name (pulled from the names of the dta2list items by rbind). (2) the output rows should not have any of the basistime dates repeated (maybe I misstated the problem); I need the max fcst value by basistime, but also list the date value for that row; for example: Then try out my code replacing dta2list <- split( dta2, dta2$date ) with dta2list <- split( dta2, dta2$basistime ) and %>% group_by( date ) with %>% group_by( basistime ) Please study how the code works and ask questions based on gaps in that knowledge rather than how the results are not what you expected. This mailing list is not a do-your-work-for-you coding service. Some help pages you should look at include: ?rownames ?split ?lapply ?do.call ?rbind ?group_by ?do You might also find [1] helpful in general, and [2] helpful for understanding dplyr. [1] H. Wickham, The Split-Apply-Combine Strategy for Data Analysis, Journal of Statistical Software, vol. 40, no. 1, Apr. 2011. [2] H. Wickham and G. Grolemund, R for Data Science. OReilly UK Ltd, 2017. URL: https://r4ds.had.co.nz. 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 very close to what I need. The basistime dates are all unique, with the max fcst value for the available basistime dates; but I additionally need the corresponding 'date' value. Best, Tom On Thu, Oct 26, 2017 at 1:28 AM, Jeff Newmillerwrote: 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
Re: [R] Help needed with aggregate or other solution
Hi Jeff, Thank you for the suggestions -- I appreciate your help. Unfortunately, the result2 has two problems... (1) there are now 3 date columns (it looks like 2 cols are merged into 1 col) (2) the output rows should not have any of the basistime dates repeated (maybe I misstated the problem); I need the max fcst value by basistime, but also list the date value for that row; for example: 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 very close to what I need. The basistime dates are all unique, with the max fcst value for the available basistime dates; but I additionally need the corresponding 'date' value. Best, Tom On Thu, Oct 26, 2017 at 1:28 AM, Jeff Newmillerwrote: > 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
Re: [R] Help needed with aggregate or other solution
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",
[R] Help needed with aggregate or other solution
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",