Suppose i have dataset $X$ and $Y$, and i want to sub-sample from $X$ so that the resulting (sample) distribution is as close to that of $Y$ as possible.

One thing i can do is subsample with probability (density) $\frac{d\_y}{d\_x}(X)$.

However, i notice that if i subsample without replacement some bias is introduced, whereas if i do so with replacement the resulting distribution is more similar to my target.

**Question: Is there any way to sample from $X$ without replacement and still achieve a distribution that is similar to $Y$?**

I have assumed the issue is sampling without replacement but if it is actually something else i am happy to be corrected.

Some code to illustrate the scenario:

```
set.seed(1235)

X=rexp(10000,rate=1)
Y=rexp(10000,rate=2)
mean(X);mean(Y)

## want to sub-sample from X to so that the resulting distribution is similar to that of Y
estimated_density=density(X,bw='SJ')
target_density=density(Y,bw='SJ')
d0=approx(estimated_density,xout=X)$y
d1=approx(target\_density,xout=X)$y
d1=ifelse(is.na(d1),0,d1)

my_sub_sample=function(replace){
  summary(replicate(500,{
    subsample=sample(X,size = 5000,prob=d1/d0,replace = replace)
    mean(subsample)   
  }))

}

my_sub_sample(replace=T) ## mean close to 0.5
my_sub_sample(replace=F) ## mean not close to 0.5

```