Skip to content
Back to formatted view

Raw Message

Message-ID: <1461334396.2445.8.camel@maladmin.com>
Date: 2016-04-22T14:13:16Z
From: Tom
Subject: Finding Highest value in groups
In-Reply-To: <1507049824.272645.1461333083629.JavaMail.yahoo@mail.yahoo.com>

Assuming your dataframe is in a variable x:

> require(dplyr)
> x %>% group_by(ID) %>% summarise(maxVal = max(Value,na.rm=TRUE))



On Fri, 2016-04-22 at 13:51 +0000, Saba Sehrish via R-help wrote:
> Hi
> 
> 
> I have two columns in data frame. First column is based on "ID" assigned to each group of my data (similar ID depicts one group). From second column, I want to identify highest value among each group and want to assign the same ID to that highest value.
> 
> Right now the data looks like:
> 
> ID    Value
> 1        0.69
> 1        0.31
> 2        0.01
> 2        0.99
> 3        1.00
> 4        NA
> 4        0
> 4        1
> 5        0.5
> 5        0.5
> 
> I want to use R program to get results as below:
> 
> ID       Value
> 1        0.69
> 2        0.99
> 3        1.00
> 4        1
> 5        0.5
> 
> Kindly guide me in this regard.
> 
> Thanks
> Saba
> 
> ______________________________________________
> 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.