Skip to content

max value

3 messages · Melissa Rosenkranz, Peter Ehlers, PIKAL Petr

#
On 2012-05-15 08:36, Melissa Rosenkranz wrote:
This is one way:

   set.seed(123)
   d <- data.frame(
        subject = gl(3,6,labels=c("01","02","03")),
        session = gl(2,3,18),
        x = gl(3,1,18),
        y = sample(11:15, 18, replace=TRUE))

   library(plyr)
   ddply(d, .(subject, session), transform,
         z = ifelse(y == max(y), 1, 0))

Peter Ehlers
1 day later
#
Hi
maximum
another
"max"
web
what
Here is another

d$z<-ave(d$y, d$subject, d$session, FUN=function(x) x==max(x))

Regards
Petr
http://www.R-project.org/posting-guide.html