[R] contingency table, several variables from dataframe

Birgitle birgit.lemcke at systbot.uzh.ch
Thu Oct 2 10:16:56 CEST 2008


Hello R-Users!

I need a little help to build up a contingency table out of several
variables.

  A<-c("F","M","M","F","F","F","F","M","F","M","F","F")
  B<-c(0,0,0,0,0,0,1,1,1,1,0,1)
  C<-c(0,1,1,1,1,1,1,1,1,0,0,0)

  ABC<-as.data.frame(cbind(A,B,C))

  ABC

   A B C
1  F 0 0
2  M 0 1
3  M 0 1
4  F 0 1
5  F 0 1
6  F 0 1
7  F 1 1
8  M 1 1
9  F 1 1
10 M 1 0
11 F 0 0
12 F 1 0

I would like to count in each variable B and C the frequencies for M and F
(variable A) and finally get the following table:

     B   C
F   3   5

M  2   3

Is there a function that can do that in one step?
Tried ?structable, ?ftable, ?xtabs, ?table but could not get what I would
like to have.

Maybe I did not use the tried functions in the right way.

Many thanks in advance for any help.

B.



-----
The art of living is more like wrestling than dancing.
(Marcus Aurelius)
-- 
View this message in context: http://www.nabble.com/contingency-table%2C-several-variables-from-dataframe-tp19775083p19775083.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list