vendredi 13 septembre 2019

Random ordered sample without replacement in R

The function RandomKSubsets from https://www.math.upenn.edu/~wilf/eastwest.pdf draws an ordered subset without replacement from a set of numbers.

`

RandomKSubsets:=proc(n,k)
local rno,east,west ;
if n<0 or k<0 or k>n then RETURN()
    elif n=0 and k=0 then RETURN([])
    else
rno:=10^(-12)*rand();
if rno<k/n then
    east:=RandomKSubsets(n-1,k-1);
    RETURN([op(east),n])
        else
    west:=RandomKSubsets(n-1,k);
    RETURN(west)
fi;fi;
end:

`

Is there a package in R that does the same thing? Or can somebody help with translating it into R?




Aucun commentaire:

Enregistrer un commentaire