[R] Calculating First Occurance by a factor
hadley wickham
h.wickham at gmail.com
Mon Mar 30 22:43:55 CEST 2009
On Mon, Mar 30, 2009 at 2:58 PM, Mike Lawrence <Mike.Lawrence at dal.ca> wrote:
> 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)]
> }
> )
Or to save a little typing:
ddply(data, .(Sub, Tr, IA), colwise(min, .(FixTime))
Hadley
--
http://had.co.nz/
More information about the R-help
mailing list