Dear Jacy, If AT and TA always one after the other, you might consider the following as an alternative:
res <- apply(a, 2, function(x) c(x[1], sum(x[2:3]), x[4] )) rownames(res) <- rownames(a)[-3] res #[,1] [,2] [,3] [,4] #AA 1 5 9 13 #AT 5 13 21 29 #TT 4 8 12 16 HTH, Jorge 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 > 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.