Skip to content
Prev 96706 / 398503 Next

random section of samples based on group membership

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
http://www.datanalytics.com
http://www.data-mining-blog.com


Quoting Wade Wall <wade.wall at gmail.com>: