Hi Jim,

Here is one way:

# data
x <- structure(list(category = structure(c(1L, 1L, 1L, 2L, 2L, 2L,
1L, 1L, 2L), .Label = c("case", "control"), class = "factor"),
    SNP1 = c(1L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 1L), SNP2 = c(0L,
    1L, 2L, 1L, 2L, 0L, 0L, 1L, 0L), SNP3 = c(2L, 1L, 2L, 0L,
    1L, 0L, 2L, 2L, 0L)), .Names = c("category", "SNP1", "SNP2",
"SNP3"), class = "data.frame", row.names = c(NA, -9L))

# transforming SNPs to factors with levels 0, 1, 2
x[, -1] <- lapply(x[, -1], function(x) factor(x, levels = 0:2))

# processing
res <- lapply(colnames(x)[-1], function(name) table(x[, 1], x[, name]))
names(res) <- colnames(x)[-1]
res

HTH,
Jorge


On Wed, Jul 27, 2011 at 12:23 AM, Jim Silverton <> wrote:

> Hello,
> I have indicators for the present of absent of a snps in columns and the
> categorey (case control column). I would like to extract ONLY the tables
> and
> the indices (SNPS) that give me 2 x 3 tables. Some gives 2x 2 tables when
> one of the allelle is missing. The data look like the matrix snpmat below:
> so the first snp should give me the following table: (aa=0, Aa=1 and AA=2)
>
>             aa         Aa         AA
> case      2            3           0
> control   2            2           0
>
> So I should not use this one or if I am using it, then I need to see  0 0
> in
> to AA column which I don't see when I use the table command in R.
>
>
>
> snpmat
>
>
> category   SNP1     SNP2     SNP3    ....     SNPN
> case           1            0            2                     1
> case           0            1            1                      2
> case           1            2            2                     0
> control         0           1             0                    1
> control         1           2            1                     2
> control         0           0            0                     0
> case            1           0            2                     2
> case            0           1            2                    1
> control          1          0            0                     1
>
>
> --
> Thanks,
> Jim.
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to