[R] for loop

Michael Dewey lists at dewey.myzen.co.uk
Tue Jan 12 18:02:53 CET 2016


Dear Maryam

Please keep the list cc'ed in as others will have better answers than me.

If dam has 700 members then sample (dam) gives you a random permutation 
of dams, each once.

I did not understand the second part as i do not think you can have 30 
sires each occurring 20 times. Did you mean 35 sires? You can follow the 
same procedure as I suggested to do that.

I think you perhaps need to re-read some introductory material as you 
are struggling over some fairly basic concepts here.

Michael.

On 12/01/2016 16:54, MARYAM wrote:
> Dear Michael,
> thanks a lot for your answering. I have question if i have 700 dam and 30 sire. how can i write my ped thad dam use only once and sire use 20 time or 1:20 dam with sire 1 then 21:40 dam with sire 2 and …
>
>
> On Dey 22, 1394 AP, at 19:52, Michael Dewey <lists at dewey.myzen.co.uk> wrote:
>
>> 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
>
>

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



More information about the R-help mailing list