[R] dplyr : row total for all groups in dplyr summarise

David Winsemius dwinsemius at comcast.net
Mon Jul 4 18:21:00 CEST 2016


> On Jul 4, 2016, at 6:56 AM, maicel at infomed.sld.cu wrote:
> 
> Hello,
> How can I aggregate row total for all groups in dplyr summarise ?

Row total … of what? Aggregate … how? What is the desired answer?



> library(dplyr)
> mtcars %>%
>  group_by (am, gear) %>%
>  summarise (n=n()) %>%
>  mutate(rel.freq = paste0(round(100 * n/sum(n), 0), "%"))
> 
> best regard
> Maicel Monzon
> 
> 
> 
> ----------------------------------------------------------------
> 
> 
> 
> 
> --
> Este mensaje le ha llegado mediante el servicio de correo electronico que ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema Nacional de Salud. La persona que envia este correo asume el compromiso de usar el servicio a tales fines y cumplir con las regulaciones establecidas
> 
> Infomed: http://www.sld.cu/
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.



More information about the R-help mailing list