-3

So I've been trying for a couple days but I can't seem to figure this out. I am trying to print the max value in a column with the corresponding date.

My theData is in the Following format:

Date         Time        Value 
20130811     9:30         12
20130811     9:31          0
20130811     9:32          1
20130812     9:30          8
20130812     9:31          99
20130812     9:32          12

The following code was suggested to me in an earlier post and works partially:

 max <- ddply(theData,.(Date),summarize, High=max(Value))

which yields:

  Date     Value 
  20130811  12
  20130812  99

I need the code to yield:

 Date      Time      Value 
 20130811   9:30       12
 20130812   9:31       99

Is there a way to do this without using a for loop?

Thanks for any help.

Junior R
  • 93
  • 2
  • 12
  • 2
    -1 As far as I can tell, you've asked this question about four times now, and had correct answers each time. As @Metrics points out, this is *exactly* the same answer given previously – alexwhan Aug 11 '13 at 23:29

1 Answers1

2

I am going to repeat my answer from the earlier post, which still is valid:

library(plyr)
ddply(mydata,.(Date),summarize,Time=Time[which.max(Value)],max.value=max(Value))


          Date Time max.value
1 20130811 9:30        12
2 20130812 9:31        99
Community
  • 1
  • 1
Metrics
  • 15,172
  • 7
  • 54
  • 83