An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090316/6b6ee2b7/attachment-0002.pl>
Select a random subset of rows out of matrix
3 messages · Haenlein.Michael, David Winsemius, Paul Hiemstra
On Mar 16, 2009, at 10:34 AM, Haenlein.Michael wrote:
Dear all, I have a large dataset (N=100,000 with 89 variables per subject). This dataset is stored in a 100.000 x 89 matrix where each row describes one individual and each column one variable. What is the easiest way of selecting a subset of let's say 1.000 individuals out of that whole matrix?
bigmatrix[ sample( 1:nrow(bigmatrix), 1000, replace=FALSE), ]
Thanks, Michael Michael Haenlein Associate Professor of Marketing ESCP-EAP European School of Management Paris, France [[alternative HTML version deleted]]
______________________________________________ R-help at 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.
David Winsemius, MD Heritage Laboratories West Hartford, CT
Hi, You could try something like this: nrow = 1000 ncol = 10 nosample = 50 m = matrix(runif(10000), nrow = nrow, ncol = ncol) # Randomly select 50 row numbers and extract the data m_subset = m[sample(1:nrow, size = nosample),] cheers, Paul
Haenlein.Michael wrote:
Dear all, I have a large dataset (N=100,000 with 89 variables per subject). This dataset is stored in a 100.000 x 89 matrix where each row describes one individual and each column one variable. What is the easiest way of selecting a subset of let's say 1.000 individuals out of that whole matrix? Thanks, Michael Michael Haenlein Associate Professor of Marketing ESCP-EAP European School of Management Paris, France [[alternative HTML version deleted]]
______________________________________________ R-help at 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.
Drs. Paul Hiemstra Department of Physical Geography Faculty of Geosciences University of Utrecht Heidelberglaan 2 P.O. Box 80.115 3508 TC Utrecht Phone: +3130 274 3113 Mon-Tue Phone: +3130 253 5773 Wed-Fri http://intamap.geo.uu.nl/~paul