[R] Calculating a table of symbol frequencies

Wollenberg, Kurt R KWollenberg at tufts-nemc.org
Thu Jan 6 17:35:37 CET 2005


Hello all:

I have a protein sequence alignment in a data frame (align1, 72 x 236),
where each row is a protein and each column a site in the alignment. AA is
vector of amino acid symbols plus "-" (gap). I can calculate amino acid
frequencies at each site by:

>align1.F <- matrix(0,nrow=22,ncol=236,dimnames=list(AA,seq(1:236)))
>for(i in 1:236)
> align1.F[names(summary(align1[[i]])),i] <-
(summary(align1[[i]])/length(align1[[i]]))

Is there a more efficient (i.e., without a loop) way to do this? Is there
some way to use table or ftable to create an 22 x 236 table of amino acid
frequencies from align1 and AA in one fell swoop?

Thanks,
Kurt Wollenberg, PhD
Tufts Center for Vision Research 
New England Medical Center
750 Washington St, Box 450 
Boston, MA, USA
kwollenberg at tufts-nemc.org 
617-636-8945 (Fax)
617-636-9028 (Lab)

The most exciting phrase to hear in science, the one that heralds new
discoveries, is not "Eureka!" (I found it!) but  "That's funny ..." 
--Isaac Asimov


********************** 
Confidentiality Notice\ **********************\      The inf...{{dropped}}




More information about the R-help mailing list