[R] aggregate empty row for pretty appearance also subtotal if possible
jim holtman
jholtman at gmail.com
Fri Oct 3 04:38:18 CEST 2008
You can also use the 'reshape' package:
> d.m <- melt(dat, measure.var='x')
> d.m
Group1 Group2 variable value
1 A Y x 1
2 B N x 1
3 A Y x 1
4 B N x 420164904
5 A N x 3
> cast(d.m, Group1+Group2~., sum, margins=TRUE)
Group1 Group2 (all)
1 A N 3
2 A Y 2
3 A (all) 5
4 B N 420164905
5 B (all) 420164905
6 (all) (all) 420164910
>
On Thu, Oct 2, 2008 at 5:46 PM, Sharma, Dhruv <Dhruv.Sharma at penfed.org> wrote:
> Hi,
> To pretty print aggregates by various dimensions I needed to add a
> empty row in output of aggregate.
>
> For example.
>
> d<-(aggregate(data[,cbind("x")], by=list(data$group1,data$group2),
> sum))
>
> Group.1 Group.2 x
> 1 A N 3
> 2 A Y 2
> 3 B N 420164905
>
> Is there a way to add an empty row between group1 and group 2.
> So that it looks like
> Group.1 Group.2 x
> 1 A N 3
> 2 A Y 2
> 3
> 4 B N 420164905
>
>
> I need to format a series of aggregates by multi dimensions and I wanted
> to break the data by empty row between group 1 that people can see some
> space.
>
> Also is there a way to add subtotals by group 1 into the mix :
> Group.1 Group.2 x
> 1 A N 3
> 2 A Y 2
> 3 5
> 4 B N 420164905
> 5 420164905
>
>
> original data is something like:
> data
> Group1 Group2 x
> A Y 1
> B N 1
> A Y 1
> B N 420164904
> A N 3
>
>
> thanks
> Dhruv
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem that you are trying to solve?
More information about the R-help
mailing list