[BioC] splitting a data frame
Jenny Drnevich
drnevich at uiuc.edu
Thu Apr 26 21:22:13 CEST 2007
Hi David,
This is a general R question and not a Bioconductor-specific
question, but... Yes, first create the vector of random numbers using
sample(). However, you don't need to use subset() to subset your
dataframe, you can just use brackets [] to subset:
rand.num <- sample(1:200, 150)
sub1.150 <- yourdataframe[rand.num,]
sub2.50 <- yourdataframe[-rand.num,]
Cheers,
Jenny
At 07:14 AM 4/26/2007, kfbargad at ehu.es wrote:
>Dear list,
>
>sorry for this very basic question but I have searched the R manual
>without success. What function do I need to randomly split a
>data.frame into two data.frames (for example a data.frame containing
>200 rows and 5 columns into two of say 150 and 50 rows each)? Should I
>first create a vector of 150 random numbers between 1 and 200 (but
>how?) and then use subset() function?
>
>Thanks in advance for your help
>David
>
>_______________________________________________
>Bioconductor mailing list
>Bioconductor at stat.math.ethz.ch
>https://stat.ethz.ch/mailman/listinfo/bioconductor
>Search the archives:
>http://news.gmane.org/gmane.science.biology.informatics.conductor
Jenny Drnevich, Ph.D.
Functional Genomics Bioinformatics Specialist
W.M. Keck Center for Comparative and Functional Genomics
Roy J. Carver Biotechnology Center
University of Illinois, Urbana-Champaign
330 ERML
1201 W. Gregory Dr.
Urbana, IL 61801
USA
ph: 217-244-7355
fax: 217-265-5066
e-mail: drnevich at uiuc.edu
More information about the Bioconductor
mailing list