I am attempting to sample 10 markers from each chr, 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 resampling when the max distains is greater than 14. Example code is below.
I have gon 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. Rodrigo #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) selectmarkers<- function(n=10){ 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 [[alternative HTML version deleted]] ______________________________________________ R-help@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.