Skip to content

Calculating First Occurance by a factor

3 messages · Michael Lawrence, Jason Gullifer, Hadley Wickham

#
I discovered Hadley Wickham's "plyr" package last week and have found
it very useful in circumstances like this:

library(plyr)

firstfixtime = ddply(
       .data = data
       , .variables = c('Sub','Tr','IA')
       , .fun <- function(df){
               df$FixTime[which.min(df$FixInx)]
       }
)

  
    
#
On Mon, Mar 30, 2009 at 2:58 PM, Mike Lawrence <Mike.Lawrence at dal.ca> wrote:
Or to save a little typing:

ddply(data, .(Sub, Tr, IA), colwise(min, .(FixTime))

Hadley