1

I'm trying to use R to find the max value of each day for 1 to n days. My issue is there are multiple values in each day. Here is my code. After I run it, it shows same answer for each day:

20130311   12
20130311   12

In the earlier post, I was suggested to use the following approach

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

My data is as follows:

Day           Time              Value 
20130310     09:30:00             5      
20130310     09:31:00             1 
20130310     09:32:00             2
20130310     09:33:00             3
20130311     09:30:00             0
20130311     09:31:00             12
20130311     09:32:00             1
20130311     09:33:00             5

The solution for this was provided as:

 day         time      value
 20130310    09:30:00    5 
 20130311   09:31:00   12

Any suggestions other than using this approach?

Community
  • 1
  • 1
Junior R
  • 93
  • 2
  • 12
  • @Metrics, did you downvote for being duplicate? – Ricardo Saporta Aug 08 '13 at 23:32
  • @Dennis: Please see [here](http://meta.stackexchange.com/questions/7046/how-do-i-get-attention-for-old-unanswered-questions) – Metrics Aug 08 '13 at 23:46
  • Why not provide example data that reflects your actual issue, i.e. multiple max values per day? You will be more likely to receive helpful answers ;) – Henrik Aug 09 '13 at 00:00
  • The question has been edited to reflect the earlier question and solution. – Metrics Aug 09 '13 at 00:31
  • 1
    @Metrics, in the comment to your answer, there is the following comment: _<>_ We cannot fault a person who is new to SO for following the advice received as far as customs and norms. – Ricardo Saporta Aug 09 '13 at 00:46
  • Yes @Ricardo, you are right. But, the new data has also been updated in the earlier question (after that comment) and the solution (using plyr) has been also provided for that. – Metrics Aug 09 '13 at 00:52
  • exactly, and this question is simply saying, "hey, I still cant figure it out". No reason for the down vote ;) – Ricardo Saporta Aug 09 '13 at 01:57

1 Answers1

3

You can use data.table:

DT[, max(Value), by=Date]
#        Date V1
# 1: 20130310  5
# 2: 20130311 12

Where,

library(data.table)
DT <- data.table( theData )
Ricardo Saporta
  • 54,400
  • 17
  • 144
  • 178