Here is one way of doing it: > x <- data.frame(group=sample(1:4,100,TRUE), age=runif(100,4,80)) > tapply(x$age, x$group, function(z) mean(z[sample(seq_along(z), length(z) / > 10)])) 1 2 3 4 34.56628 58.70901 54.26239 58.89306 > >
On Wed, Mar 5, 2008 at 7:49 PM, Chang Liu <[EMAIL PROTECTED]> wrote: > > Hello Gurus: > > If I have a dataframe with one of the variables called "age" for example, and > I want to extract a random 10% of the observations from each "age" group of > the entire data frame. Do I have to double loop to split the data and then > loop again to assign random numbers? Or is there a better way to do this? > > Thanks! > Karen > > > > _________________________________________________________________ > > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? ______________________________________________ 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.