Try this:
by(x, x$Form, function(.x)rbind(.x[-3], sum(.x[2])))
On Wed, May 19, 2010 at 6:49 PM, Gerrit Draisma
<g.draisma@erasmusmc.nl>wrote:
> I am looking for the following simple question.
> I have a data frame with names and numbers, divided in categories.
> I would like to produce a text file with page breaks,
> listing the names and numbers by category,
> and totalling the numbers.
>
> Example:
>
> Name<-LETTERS[1:6]
> Score<-rep(5:8,length.out=6)
> Form<-rep(1:2,each=3)
> x<-data.frame(Name,Score,Form)
>
> This gives approximately what I need
> by(x,x$Form,function(x){x[,1:2]})
> but I would like a total added to the list.
>
> Gerrit.
>
> ______________________________________________
> 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
[[alternative HTML version deleted]]