splitting a data frame
0
0
Entering edit mode
Seth Falcon ★ 7.4k
@seth-falcon-992
Last seen 9.7 years ago
<kfbargad at="" ehu.es=""> writes: > 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? This is not a BioC specific question and would be better asked on the R-help list. Yes, you can do this by creating a vector of row indices. See help("sample"). You don't need subset. Just "[". v = sample(1:nrow(df)) df[v[1:50], ] df[v[51:nrow(df)], ] + seth -- Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research Center http://bioconductor.org
Cancer Cancer • 600 views
ADD COMMENT

Login before adding your answer.

Traffic: 762 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6