Let say I've two datasets with similar variables but different distribution. In the example below, dataset a has a variable var1 with a mean of 10 and a sd of 4. Dataset b has also variable var1 but with a mean of 8 and a sd of 4.
a <- data.frame(id=1:500,var1=rnorm(500,10,4),type="a")
b <- data.frame(id=1:300,var1=rnorm(300,8,4),type="b")
rbind(a,b) %>%
ggplot(aes(x=type,y=var1)) +
geom_boxplot()
Is there a way to filter dataset b to match dataset a's var1 distribution ? When I say match, mean and sd should be similar (not necessarly equal)
I tried using MatchIt package to match a and b dataset but it filters also some entries from dataset a.
Any idea ?
Thanks
Edit>
Here's the real shape of a and b density (from my data). a is red, b is blue
