Try this:

> key <- rownames(a)
> key[key == "AT"] <- "TA"
> do.call(rbind, by(a, key, colSums))
   V2 V3 V4 V5
AA  1  5  9 13
TA  5 13 21 29
TT  4  8 12 16


On Mon, May 11, 2009 at 4:53 PM, Crosby, Jacy R
<jacy.r.cro...@uth.tmc.edu>wrote:

> I'm working with genotype data in a frequency table:
>
> > a=matrix(1:16, nrow=4)
> > rownames(a)=c("AA","AT","TA","TT")
> > a
>   [,1] [,2] [,3] [,4]
> AA    1    5    9   13
> AT    2    6   10   14
> TA    3    7   11   15
> TT    4    8   12   16
>
> 'AT' and 'TA' are essentially the same, and I'd like to combine (add) the
> rows to reflect this. The final matrix should be:
>
>   [,1] [,2] [,3] [,4]
> AA    1    5    9   13
> AT    5    13   21   29
> TT    4    8   12   16
>
> Is there a fast way to do this?
>
> Thanks in advance!
>
> Jacy Crosby
> jacy.r.cro...@uth.tmc.edu
>
>
>        [[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<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

        [[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