Hi Silvano,

How about this?

id <- seq(80)
weight <- runif(80)

# randomize 4 groups with 'sample' function
group <- sample(rep(seq(4),20))
dat <- cbind(id, weight, group)

# ordered dataset by group
res <- data.frame(dat[order(group),])

# get mean and variance for each group
aggregate(res$weight, list(group=res$group), mean)
aggregate(res$weight, list(group=res$group), var)

Cheers,
Charles



On Fri, Aug 23, 2013 at 9:03 AM, Silvano <silvano@uel.br> wrote:

> Hi,
>
> I have a set of 80 animals and their respective weights. I would like
> create 4 groups of 20 animals so that the groups have means and variances
> with values ??very close.
> How can I make this randomization in R?
>
> Thanks,
>
> ------------------------------**--------
> Silvano Cesar da Costa
> Departamento de Estatística
> Universidade Estadual de Londrina
> Fone: 3371-4346
>
> ______________________________**________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>
> PLEASE do read the posting guide http://www.R-project.org/**
> posting-guide.html <http://www.R-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Charles Determan
Integrated Biosciences PhD Candidate
University of Minnesota

	[[alternative HTML version deleted]]

