[R] More than on loop??

David Winsemius dwinsemius at comcast.net
Sun Jan 17 01:48:05 CET 2010


On Jan 16, 2010, at 7:09 PM, che wrote:

>
> hello every one,
>
> How to function more than one loop in R?

for (i in 1:3) {
       for (j in 1:2) {
          for (k in letters[1:4]) { print(paste(i , j,  k) )  }
                }      }

I'm afraid I develop a strong suspicion that a problem is homework  
when I am told it should be solved with a particular control structure  
and I then see no code.

-- 
David.


> I have the following problem to be
> solved with the a method of three loops, can you help me please?
>
> The data is attached with this message.
>
> The data is composed of two parts, cleaved (denoted by “cleaved”)  
> and non
> cleaved (denoted by “noncleaved”).
> • to access to the ith peptide, you can use X$Peptide[i]
> • to access to the ith label, you can use X$Label[i]
>
> define a set of amino acids using string or other format if you want
> amino.acid<-"ACDEFGHIKLMNPQRSTVWY"
> define two matrices with initialised entries, one for cleaved   
> peptides and
> one for none-cleaved peptides
> • matrix(0,AA,mer),where AA is the number of amino acids, and mer is  
> the
> number
> of residues detected from data using the nchar function
> • both matrices have the same size, the number of rows being equal  
> to the
> number
> of amino acids and the number of columns being equal to the number of
> residues
> in peptides
>
>
> use one three-loop structure to detect the frequency of amino acids in
> cleaved peptides
> and one three-loop structure to detect the frequency of amino acids in
> non-cleaved
> peptides. They should not be mixed in one three-loop structure. The  
> best way
> to
> handle this is to use a function. The three-loop structure is  
> exampled as
> below
> for(i in 1:num)#scanning data for all peptides, where num means the  
> number
> of peptides
> {
> for(j in 1:mer)#scanning all residues in a peptide
> {
> for(k in 1:AA)#scanning 20 amino acids
> {
> #actions
> }
> }
> }
> http://n4.nabble.com/file/n1015851/hiv.dat hiv.dat
> -- 
> View this message in context: http://n4.nabble.com/More-than-on-loop-tp1015851p1015851.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at 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.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT



More information about the R-help mailing list