[R] contingency table

Rolf Turner rolf.turner at xtra.co.nz
Wed Dec 21 05:53:44 CET 2011


Do you actually know what "contingency table" means?

The tables in your example make no sense at all as contingency
tables *especially if "obs" means "observed" and "exp" means
"expected".

You can, however, extra the tables in the manner which you seem
to desire, as follows:  Let your data object be called "dat".  (And
surely this object is either a data frame or a matrix --- judging by
the display --- and *NOT* a list.  Learn to use correct terminology
and you will be much more likely to get useful replies to your questions.)

dat <- as.matrix(dat) # To make sure it's a matrix r.t. a data frame.
xxx <- lapply(1:nrow(dat), 
function(i,x){matrix(x[i,],ncol=2,byrow=TRUE)},x=dat)

Now "xxx" is a (genuine!) list, and the i-th entry of this list is the 
i-th table from
your "required" set of tables.  E.g.:

xxx[[3]]
         [,1]   [,2]
[1,]      3      7
[2,]  435  525

     cheers,

         Rolf Turner

On 21/12/11 07:36, reena wrote:
> This is my list.
> obs1    obs2    exp1     exp2
>
> 3           8          725      875
> 0           0           58        70
> 3           7          435      525
> 10         7          754      910
> 0           1          145     175
>
> and i want result in contingency table as
>
> obs       3                8
> exp    725          875
>
> next table will be
>
> obs    0         0
> exp   58       70
>
> and so on...
>
> --
> View this message in context: http://r.789695.n4.nabble.com/contingency-table-tp4217741p4218845.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list