[R] FW: Select a random subset of rows out of matrix
Paul Hiemstra
p.hiemstra at geo.uu.nl
Mon Mar 16 15:48:32 CET 2009
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
More information about the R-help
mailing list