# Sum of contingency table

This is probably a dumb question but when I make a contingency table like this :

``````round(100*(prop.table(addmargins(table(commun\$grp,commun\$sexe)))),2)

``````

I have this result :

When I juste made it with my proportions I have this :

``````addmargins(table(commun\$grp,commun\$sexe))
``````

It's probably a dumb question by I don't understand why my percentages total is 25 and not 100%. Thank you for your time.

because prop.table is doesnt know what number is a margin or not, so it does what it does and tell you the proportion of each value to the sum of all the values. presumably your table with the margins added, sums up to 1176 of which 294 is 25%

Oh I see, and how can I do to modify this?

if your intention is to calculate proportions on the non margins, then simply dont add the margins before you calculate those proportions ...

If you are asking how to have proportional margins, then simply add the margins to your proportions table ?

``````addmargins(prop.table(table(iris\$Species)))

setosa versicolor  virginica        Sum
0.3333333  0.3333333  0.3333333  1.0000000
``````

i.e. they sum to 1

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.