[R] printing a dataframe by categories

Gerrit Draisma g.draisma at erasmusmc.nl
Wed May 19 23:49:40 CEST 2010


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.



More information about the R-help mailing list