Skip to content
Prev 249199 / 398498 Next

Finding the maximum in a particular group in a dataframe

On Feb 2, 2011, at 3:48 AM, Asan Ramzan wrote:

            
You need to use tapply on the names of the columns , not on the values:

tapply(GPR119data$responce, GPR119data$condition, max)

 > tapply(GPR119data$responce, GPR119data$condition, max)
       con   GPR119a   GPR119b   GPR119c   GPR119d   GPR119e   GPR119f
0.3350084 0.6451204 0.8240356 0.5729588 0.3099644 0.4677268 1.0184191

Then you can choose the GPR119a  value for further examination or  
display;

 > tapply(GPR119data$responce, GPR119data$condition, max)["GPR119a"]
   GPR119a
0.6451204
I'm guessing from this display that when you read this data in you  
used the default separator which is white-space and that does not  
include commas. In addition to the above, try adding sep="," in your  
read.table function.
David Winsemius, MD
West Hartford, CT