I tried cbind, it works.

moms<-read.delim("females.txt", sep =" ",stringsAsFactors=FALSE,header=TRUE)
dads<-read.delim("males.txt", sep =" ",stringsAsFactors=FALSE,header=TRUE) 

output_offspring <-
cbind(moms[,c(1,sample((2:5),2))],dads[sample(nrow(dads),nrow(moms),replace=TRUE),c(1,sample((2:5),2))])

write.table(output_offspring,"offspring_7.txt",row.names=F,col.names=c("momID","A1","A2","dadID","A3","A4"),quote=F)
 

I hope someone can give a solution with matrix operation.

And, it seems that there are 4 repeated IDs in females.

-----
A R learner.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/sample-tp2218361p2219047.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
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.

Reply via email to