Hi all,
I have a matrix of 474 rows (samples) with 565 columns (variables).
each of the 474 samples belong to one of 120 groups, with the
groupings as a column in the above matrix. For example, the group
column would be:
1
1
1
2
2
2
.
.
.
120
120
I want to randomly select one from each group.
Dear Wade,
Say that your groups are
groups - sort(sample(1:10, 100, replace = TRUE))
Create a dummy
rows - 1:length(groups)
Then
tapply( rows, groups, function(x) sample(x, 1))
does the trick to select the row numbers you need for your sampling.
Sincerely,
Carlos J. Gil Bellosta
Well, how you do it might be a matter of taste with respect to how you
want the results.
You could try using by with sample
by(x,x[,3],function(y){y[sample(nrow(y),1),]})
This will return a list with one list element for each sample group.
You can the combine the list back into a matrix.
On Mon, 24 Jul 2006 11:18:10 -0400,
Wade Wall [EMAIL PROTECTED] wrote:
Hi all, I have a matrix of 474 rows (samples) with 565 columns
(variables). each of the 474 samples belong to one of 120 groups, with
the groupings as a column in the above matrix. For example, the group
column would be: