[R] Re : LOOPS

Yuandan Zhang yzhang4 at pobox.une.edu.au
Mon Dec 6 06:34:59 CET 2004


On Mon, 6 Dec 2004 13:36:37 +1300
ssim at lic.co.nz wrote:

> Dear lists,
> 
> I want to construct a loop in R, but don't know how to do it. I can do it
> in SAS, but I prefer in R  (which I am hoping I will off SAS for good
> soon). Could anyone help me to convert the SAS codes to equivalent R codes.
> 
> Basically, the following codes were written to establish the sire gametes
> or phases for daughter design for one markers two alleles.
> 
> Here are the SAS code:
> 

You may try this code. There may be better code from others.

m<-array(0, 795) #phase
for ( i in 1:744) {  # sire
  for (j in 745:1540) { # progeny
    if (sire[j] == anim[i] ) {  #check if the progeny j is sired by animal i
      if (m1[j]==m1[i]  &&  m2[j]==m2[i] ) { m[j]=0; next}
      if ( m1[j]==m1[i]) { m[j] = 1; next}
      if (m1[j]==m2[i]) { m[j==2; next}
  
.....

    }
  }
}   




> do i=1 to 744;
>       do j=745 to 1540;
>             m[j]=0;
>             if sire[j]=anml[i] then do;
>                 if m1[j]=m1[i]  and m2[j]=m2[i] then m[j]=0;
>                 else if m1[j]=m1[i] then m[j] =1;
>                 else if m1[j]=m2[i] then m[j==2;
>                 else if m2[j]=m1[i] then m[j]=1;
>                 else if m2[j]=m2[i] then m[j]=2;
>                 else m[j]=0;
>             end do;
>      end;
> end;
> 
> 
> Thanks Stella
> ___________________________________________________________________________
> This message, including attachments, is confidential. If you...{{dropped}}
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


-- 

--
Yuandan Zhang, PhD

Animal Genetics and Breeding Unit
The University of New England
Armidale, NSW, Australia, 2351

E-mail:   yzhang4 at metz.une.edu.au
Phone:    (61) 02 6773 3786
Fax:      (61) 02 6773 3266
http://agbu.une.edu.au
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  AGBU is a joint venture of NSW Primary Industries 
  and The University of New England to undertake 
  genetic R&D for Australia's Livestock Industries           
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~




More information about the R-help mailing list