On Wed, 2006-04-19 at 16:39 +0200, Fredrik Karlsson
wrote:> 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?
I may be missing what you are trying to do, since we don't have your
data to reproduce the output. However, you might want to look at the
ctab() function in the 'catspec' package on CRAN by John Hendrickx.
It builds on the ftable() and prop.table() functions to generate
formatted n-way percentage tables.
HTH,
Marc Schwartz