On Thu, Jul 2, 2009 at 8:15 AM, James Martin<just.strut...@gmail.com> wrote: > Hadley, Sunil, and list, > > This is not quite doing what I wanted it to do (as far as I can tell). I > perhaps did not explain it thoroughly. It seems to be sampling one value > for each day leaving ~200 observations. I need for it randomly chose one hab > value for each bird if there is more than one value for a given day, I will > try and example below. > > id,date,location2,hab > > 1,05/23/06,0,1 > 1,05/23/06,0,2 > 1,05/23/06,0,1 > > So in this case the animal was located 3 times on may 23rd but I only want > one of the locations and instead of arbitrarily choosing one I wanted to > randomly sample one.
ddply(df, c("date", "location"), function(df) df[sample(nrow(df), 1), ]) Hadley -- http://had.co.nz/ ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.