[R] How to apply a function to subsets of a data frame *and* obtain a data frame again?

Hadley Wickham hadley at rice.edu
Wed Aug 17 13:38:07 CEST 2011


> The following example does what you want using ddply:
>
> library(plyr)
> edfPerGroup = ddply(df, .(Group), summarise, edf = edf(Value), Value =
> Value)

Or slightly more succinctly:

ddply(df, .(Group), mutate, edf = edf(Value))

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/



More information about the R-help mailing list