[R] prop.table on three-way table?

Fredrik Karlsson dargosch at gmail.com
Wed Apr 19 16:39:19 CEST 2006


Dear list,

I am trying to create a three-way table with percent occurrence
instead of raw frequencies. However, I cannot get the results I
expected:

I have the following table:

> ftable(table( mannerDF$agem, mannerDF$target, mannerDF$manner ))
<snip>
50 bak             0         0       0     0       1         0
   pak             0         0       0     0       3         0
   sak             0         1       0     0       0         0
   spak            0         0       0     0       0         0

Now, If I use the prop-table function, I newer get a 1 ratio in any cell:



With 'margin=1':

50 bak    0.00000000 0.00000000 0.00000000 0.00000000 0.20000000 0.00000000
   pak    0.00000000 0.00000000 0.00000000 0.00000000 0.60000000 0.00000000
   sak    0.00000000 0.20000000 0.00000000 0.00000000 0.00000000 0.00000000
   spak   0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000

With 'margin=2':

50 bak   0.000000000 0.000000000 0.000000000 0.000000000 0.004347826 0.000000000
   pak   0.000000000 0.000000000 0.000000000 0.000000000 0.010752688 0.000000000
   sak   0.000000000 0.005747126 0.000000000 0.000000000 0.000000000 0.000000000
   spak  0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000

With 'margin=3':

50 bak   0.000000000 0.000000000 0.000000000 0.000000000 0.001373626 0.000000000
   pak   0.000000000 0.000000000 0.000000000 0.000000000 0.004120879 0.000000000
   sak   0.000000000 0.008695652 0.000000000 0.000000000 0.000000000 0.000000000
   spak  0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000

What I was looking for is this:


50 bak             0         0       0     0       1         0
   pak             0         0       0     0       1         0
   sak             0         1       0     0       0         0
   spak            0         0       0     0       0         0

(With more digits)

Am I doing something stupid?

/Fredrik




More information about the R-help mailing list