How to create a random sample from a distribution in which every value must come atleast once

i have a vector which has 100 values i have to create another vector with random distribution of these 100 values but the length should be 200.
and every value in 1st vector must be in second vector at least once.

i am new to the R programming please help.

Welcome to the community!

If this is the only constraint, then you can do something like this:

  1. Suppose x is the vector of elements of length n.
  2. Suppose you need a sample of size m from this population, where each element must occur at least r times.
  3. Generate a WR sample of size m - (n * r) from this population, say z.
  4. Construct y by concatenating z with r copies of x.
  5. A permutation of y should give you the desired result.

The R functions that you need for this are rep and sample.

Hope this helps.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.