[R] aggregate without removing empty subset
Henrique Dallazuanna
wwwhsd at gmail.com
Mon Mar 15 18:17:21 CET 2010
Try this:
apply(m, 2, tapply, part, mean)
On Mon, Mar 15, 2010 at 2:10 PM, Christophe Genolini
<cgenolin at 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 at 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
More information about the R-help
mailing list