[R] RTable width sum colum

Marc Schwartz marc_schwartz at comcast.net
Mon Oct 8 17:41:58 CEST 2007


On Mon, 2007-10-08 at 16:18 +0200, Alessandra Marmo wrote:
> Hello
> I need to print table width "colum sum" like
> X    V1    V2    TOT
> A    2    3            5
> B    1    6            7
> C    4    6           10
> 
> how i can do it by table function?
> 
> Thanks
> 
> Alessandra

Presuming that your object above is a data frame, you can add a new
column using cbind():

> tab
  X V1 V2
1 A  2  3
2 B  1  6
3 C  4  6


> cbind(tab, TOT = tab$V1 + tab$V2)
  X V1 V2 TOT
1 A  2  3   5
2 B  1  6   7
3 C  4  6  10

See ?cbind.

For actual R tables, you can use ?addmargins

HTH,

Marc Schwartz



More information about the R-help mailing list