Reputation: 93
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?
Upvotes: 1
Views: 1038
Reputation: 55350
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 )
Upvotes: 3