Skip to content
Prev 334399 / 398506 Next

dataframe manipulation

What about:

lapply(levels(d$fac), function(x)head(d[d$fac == x,], 1))


Thanks for the reproducible example. If you put set.seed(123) before
the call to sample, then everyone who tries it will get the same data
frame d.

Sarah
On Fri, Dec 13, 2013 at 4:15 PM, Gang Chen <gangchen6 at gmail.com> wrote: