Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Random sampling by category, different number of samples needed per category in R [duplicate]

$
0
0

This question already has an answer here:

I have a question to do some random sampling in R. I have two datasets. One dataset, say df1, is organized where each observation is a sample, and the location from which the sample was collected is under the variable "loc". "loc" is set as a character. An example data layout is shown below.

    ID loc x1 x2 x3 
    1  A   x  x  x
    2  A   x  x  x
    3  A   x  x  x
    4  B   x  x  x
    5  B   x  x  x 
    6  C   x  x  x 
    7  C   x  x  x 
    8  C   x  x  x
    9  C   x  x  x
    etc.

The second dataset, say df2, is a list of all of the locations and the number of random samples required from each location. It looks like this:

    loc n
    A   2
    B   1
    C   3

I am wondering how to take different numbers of random samples by group, where the number of samples required is denoted in df2.


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>