[R] labels and counting

Gabor Grothendieck ggrothendieck at myway.com
Thu Dec 30 21:29:33 CET 2004

dax42 <Dax42 <at> web.de> writes:

: Hello,
: I have got the following problem:
: given is a large string sequence consisting of the four letters "A" "C" 
: "G" and "T" (as before). Additionally, I have got a second string 
: sequence of the same length giving a label for each character. The 
: labels are "+" and "-".
: Now I would like to create an 8x8 matrix which contains the numbers on 
: how often we see all possible pairwise combinations, for example "A" 
: with the label "+" followed by "C" with the label "+" or "T"->"C" with 
: the labels "-"->"+" etc.
: Of course I can just use loops to "walk" along the sequence, but as you 
: have shown me so much better solutions in response to my last mail, I 
: thought you might be able to help and improve my R skills even further 

This is quite similar to your prior question.  Use this as your

f <- factor( paste(s1, s2, sep = "."), 
	levels = levels(interaction(c("A","C","G","T"), c("-","+")) ) 

and process it with the same table expression as last time:

table( f[-length(f)], f[-1] )

More information about the R-help mailing list