[R] for loop

Michael Dewey lists at dewey.myzen.co.uk
Tue Jan 12 17:22:31 CET 2016


Dear Maryam

sample(dam) would give you a random permutation of dams
sample(c(sire, sire)) would give you a random permutation of sires, each 
twice.

Does that help?

On 12/01/2016 05:53, maryam firoozi via R-help wrote:
>
> Dear mr/madam
> I want to mak a matrix with 10 row and 3 column . this matrix is pedigree. my input
> sire<- c(1,2,3,4,5)
> count<- 0
> sire<- cbind(sire,count)
> dam<- c(1,2,3,4,5,6,7,8,9,10)
> ped<-mstrix(NA,nrow=10,ncol=3)
> for(i in 1:10){
> Sire<- sample(sire[,1],1)
> a<- which(sire[,1]==Sire)
> if(a){sire[a,2]<-sire[a,2]+1}
>
> Dam<- sample(dam,1)
> ped[i,1]<- 1:10
> ped[i,2]<- Sire
> ped[i,3]<- Dam}
> i cant write a code that each sire use only twic not more in ped and Dam use only once.
> can you help me?
> sincerely
> firoozi
> Sent from my iPhone
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

-- 
Michael
http://www.dewey.myzen.co.uk/home.html



More information about the R-help mailing list