Try this: apply(m, 2, tapply, part, mean)
On Mon, Mar 15, 2010 at 2:10 PM, Christophe Genolini <cgeno...@u-paris10.fr> wrote: > Hi the list, > > As it is say in its doc, the aggregate function remove empty subsets. Is it > possible to NOT remove empty subset ? > --- 8< ------- > m <- matrix(1:12,4) > part <- factor(c("A","B","A","B"),levels=c("A","B","C")) > aggregate(m,list(part),mean) > > ### I get: > # Group.1 V1 V2 V3 > # 1 A 2 6 10 > # 2 B 3 7 11 > # > ### I would like: > # Group.1 V1 V2 V3 > # 1 A 2 6 10 > # 2 B 3 7 11 > # 3 C NA NA NA > --- 8< ------ > > > Thanks > Christophe > > ______________________________________________ > 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. > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O ______________________________________________ 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.