[R] Set up a while loop

From: Rodrigo Gularte <rjgularte_at_ucdavis.edu>
Date: Tue, 18 Nov 2008 09:52:08 -0800

I am attempting to sample 10 markers from each chromosome, with a maximum distance of 14, calculated by the location of the marker in each chromosome as loc[i+1] - loc[i]. I presume the easiest way to do this is with a while loop, so that the function keeps re-sampling when the max distains is greater than 14. Example code is below.

I have gone as far as to select markers and calculate the distances, A while loop with set with max(distances)>14 should work, but I'm not sure where to set this.
Any help would be appreciated.


#some markers, chromosomes and locations
loc<- rep(1:100, 5)
marker<- paste("A", seq(1:500), sep="")
chr<- rep(1:5, rep(100,5))
mm<- data.frame(marker, chr, loc)

  tapply(mm$marker, mm$chr, function(m){

# while (max(distances) > 14) {

     mars<- sort(sample(m, n))

    distances<- rep(NA, (length(mars)-1))

    for (i in 1:(length(mars)-1)) {

      distances[i]<- mm[mars[i+1], 'loc'] - mm[mars[i], 'loc']
      } #end of for loop

# } # end of while loop

    return (mars)

    } # end of tapply f(m)
  ) #tapply
} # end of selectmarkers    

Rodrigo J Gularte

Juan Medrano Laboratory

Department of Animal Science

University of California, Davis

Tel: (530) 752-4509  

        [[alternative HTML version deleted]]

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. Received on Tue 18 Nov 2008 - 18:29:52 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 18 Nov 2008 - 18:30:25 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive