Hello, I'd like to think all respondents for your advises and suggestions. I am sorry for not including the ordered gene expression data frame (largedf) since it is large. The problem is solved now by Greg Down by including the command: rm(.Random.seed) in the code, perhaps I used some R packges to process that expression data which set the seed on the Random Number Generator to a fixed value. Thanks again, Joshua
----- Original Message ----- From: "Charles C. Berry" <[EMAIL PROTECTED]> To: "Shuhua Zhan" <[EMAIL PROTECTED]> Cc: r-help@r-project.org Sent: Thursday, October 30, 2008 9:07:09 PM GMT -05:00 US/Canada Eastern Subject: Re: [R] why does sample(x, n) give the same n items in every separate runs? Run help.request(). In particular you need to attend to this part: Have you written example code that is - minimal - reproducible - self-contained - commented using data that is either - constructed by the code - loaded by data() - reproduced using dump("mydata", file = "") have you checked this code in a fresh R session (invoking R with the --vanilla option if possible) and is this code copied to the clipboard? (y/n) ---- Once you get this far and can honestly type 'y', if you have not found your error, you are ready to post a query. HTH, Chuck On Thu, 30 Oct 2008, Shuhua Zhan wrote: > Hello R users, > I have gene expression data of two groups of genes (large and small). Gene > expression intensities of those genes are classified into 1 to 10 levels. > What I want is to make a random set of genes that have the same levels as the > small group from large group using sample(). > > I used smallvec to hold the number of genes in each levels (1 to 10) for > small group, largevec for large group. I ordered the gene expression data > frame of large group (largedf) by the levels and randomly chose the genes > with same level as small group. Using the code below I can get the random set > of genes from lagre group with same levels for small group. But I got the > same set of genes when I run the code in every other runs in Linux. This > gives me a doubt in my result. > > smallvec<-c(8,12,9,6,13,20,16,11,8,5) ## the No. of genes in levels 1 to 10 > largevec<-c(400,300,550,600,210,420,380,600,450,500) > generdm<-c() ## a random set of genes > for( i in 1:length(smallvec)){ > > generdm<-c(generdm,sample(rownames(largedf)[sum(largevec[0:(i-1)],1):sum(largevec[0:i])],smallvec[i])) > ## rownames(largedf) gives gene names ordered by levels in large group > } > > Could you please help me out? > Thanks a lot!! > Josh > > ______________________________________________ > 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. > Charles C. Berry (858) 534-2098 Dept of Family/Preventive Medicine E mailto:[EMAIL PROTECTED] UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901 ______________________________________________ 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.