Rtist
August 17, 2019, 3:52pm
1
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:
Suppose x
is the vector of elements of length n
.
Suppose you need a sample of size m
from this population, where each element must occur at least r
times.
Generate a WR sample of size m - (n * r)
from this population, say z
.
Construct y
by concatenating z
with r
copies of x
.
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
system
Closed
August 24, 2019, 4:21pm
3
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.