1
$\begingroup$

There is a set A having $N$ elements. Based on set A, I would like to construct $M$ groups, where each group has $P$ elements. Naturally, $M P <N$. All of those elements in the $M$ groups are sampled from set A by following the two criteria, they are different with each other; the sampling probability for each of these MP elements are the same.

Which kind of sampling method should I use? How to do that in R?

$\endgroup$
  • $\begingroup$ What exactly do you mean by "based on set A"? And you write that "Naturally, M *P", what do you mean by that? Did you mean that $M\times P=N$? $\endgroup$ – Stephan Kolassa Nov 29 '12 at 16:23
  • $\begingroup$ "based on set A" means that all of those MP elements are sampled from A. MP can be smaller than N. $\endgroup$ – user3269 Nov 29 '12 at 16:35
  • $\begingroup$ I edited my answer based on your comment. Is this what you need? $\endgroup$ – Stephan Kolassa Nov 29 '12 at 16:40
1
$\begingroup$
A <- LETTERS[1:20]
M <- 4
P <- 3
matrix(sample(A,size=M*P),nrow=M, ncol=P)

Then each row of the matrix gives you one group of size $P$. Alternatively, you can sample with replacement:

matrix(sample(A,size=M*P,replace=TRUE),nrow=M, ncol=P)
| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks. Can I understand the usage of "sample" this way, if I do not include the parameter of "prob" when using sample. All of the sampled ones are given the same probability, 1/MP. Otherwise, I can use parameter "prob" to control the selection probability for each sampled one. $\endgroup$ – user3269 Nov 29 '12 at 16:54
  • $\begingroup$ Exactly correct! $\endgroup$ – Stephan Kolassa Nov 29 '12 at 17:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.