[R] is there an equivalent of prop.table but for counts

markleeds at verizon.net markleeds at verizon.net
Wed Jul 2 04:41:39 CEST 2008


I have a simple table below called temptable and i want to obtain the 
same structure that prop.table creates except get the counts
rather than the proportions. margin.table seems to create one table with 
columns and rows whereas I am looking for  the three table
type structure that prop.table gives. Thanks.

temptable<-structure(c(0L, 2L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 
0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 1L, 1L, 1L, 0L, 0L, 2L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 1L, 0L, 1L, 0L,
0L, 2L, 1L, 0L, 1L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 0L,
1L, 0L, 1L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L,
0L, 0L, 3L), .Dim = c(8L, 4L, 3L), .Dimnames = structure(list(
     c("(-1,-0.75]", "(-0.75,-0.5]", "(-0.5,-0.25]", "(-0.25,0]",
     "(0,0.25]", "(0.25,0.5]", "(0.5,0.75]", "(0.75,1]"), 
c("(-Inf,-0.001]",
     "(-0.001,0]", "(0,0.001]", "(0.001, Inf]"), c("Neutral",
     "Negative", "Positive")), .Names = c("", "", "")), class = "table")

proptable <- prop.table(temptable,margin=c(1,2))
print(proptable)

margintable <- margin.table(temptable,margin=c(1,2))
print(margintable)



More information about the R-help mailing list