Hi:

Here are three more 'solutions' using packages doBy, plyr and data.table.

###  For illustration: maxima for all mouce/GPR* conditions
(1) doBy:

library(doBy)
dfsub <- subsetBy( ~ 1, subset = condition != 'con', data = df)
summaryBy(responce ~ mouce + condition, data = dfsub, FUN = max)
  mouce condition responce.max
1    KO   GPR119a    0.6451204
2    KO   GPR119b    0.8240356
3    KO   GPR119c    0.5729588
4    KO   GPR119d    0.3099644
5    KO   GPR119e    0.4677268
6    KO   GPR119f    1.0184191

# In fact, the subsetBy() call is superfluous, since we can also use
summaryBy(responce ~ mouce + condition, data = subset(df, condition !=
'con'), FUN = max)

(2) plyr, using function ddply():

library(plyr)
ddply(subset(df, condition != 'con'), .(mouce, condition), summarise,
        maxresp = max(responce))

<output same as doBy>

(3) data.table:

library(data.table)
dt <- data.table(df)
dt[condition != 'con', list(maxresp = max(responce)), by = 'mouce,
condition']
     mouce condition   maxresp
[1,]    KO   GPR119a 0.6451204
[2,]    KO   GPR119b 0.8240356
[3,]    KO   GPR119c 0.5729588
[4,]    KO   GPR119d 0.3099644
[5,]    KO   GPR119e 0.4677268
[6,]    KO   GPR119f 1.0184191

# Plus aggregate(), in version 2.11.0 or later - it now takes a formula, so
it behaves
# the same as summaryBy():
aggregate(responce ~ mouce + condition, data = subset(df, condition !=
'con'), FUN = max)

<output same as plyr and doBy>

If all you want is condition GPR119a, then either of the following work:

# plyr: (summarise() replaces ddply() when there is no grouping variable)
summarise(subset(df, condition == 'GPR119a'), maxresp = max(responce))
    maxresp
1 0.6451204
# data.table (define dt as a data table first per above)
dt[condition == 'GPR119a', list(maxresp = max(responce))]
       maxresp
[1,] 0.6451204

Some of the earlier responses show how to get your result a little more
easily for this particular problem, but when your summarization needs are
more complex, these packages come in very handy.

HTH,
Dennis

On Tue, Feb 1, 2011 at 11:05 AM, A. Ramzan <ar562@cam.ac.uk> wrote:

> Hello
>
> I am trying to find a way to find the max value, for only a subset of a
> dataframe, depending on how the data is grouped for example,
>
> How would I find the maxmium responce, for all the GPR119a condition below:
>
> responce,mouce,condition
> 0.105902,KO,con
> 0.232018561,KO,con
> 0.335008375,KO,con
> 0.387025433,KO,GPR119a
> 0.576769897,KO,GPR119a
> 0.645120419,KO,GPR119a
> 0.2538608,KO,GPR119b
> 0.183061952,KO,GPR119b
> 0.824035587,KO,GPR119b
> 0.399201597,KO,GPR119c
> 0.417006618,KO,GPR119c
> 0.572958834,KO,GPR119c
> 0.229467444,KO,GPR119d
> 0.294089745,KO,GPR119d
> 0.309964445,KO,GPR119d
> 0.30474325,KO,GPR119e
> 0.159374839,KO,GPR119e
> 0.467726848,KO,GPR119e
> 1.01841912,KO,GPR119f
> 0.423028621,KO,GPR119f
> 0.223588597,KO,GPR119f
>
> Thank
>
> ______________________________________________
> R-help@r-project.org mailing list
> 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.
>

	[[alternative HTML version deleted]]

