Suppose I have a data frame df:
set.seed(123)
n1 <- 5
n2 <- 8
DVm <- rnorm(n1, 180, 10)
DVf <- rnorm(n2, 175, 6)
df <- data.frame(DV=c(DVm, DVf),
IV=factor(rep(c("m", "f"), c(n1, n2))))
df
DV IV
1 174.3952 m
2 177.6982 m
3 195.5871 m
4 180.7051 m
5 181.2929 m
6 185.2904 f
7 177.7655 f
8 167.4096 f
9 170.8789 f
10 172.3260 f
11 182.3445 f
12 177.1589 f
13 177.4046 f
What I wanted is to create a new data frame by sampling n1 new DV with replacement for IV=="m" and n2 new DV with replacement for IV=="f" so that the new data frame will have same dimensions and has sampled within each group of m and f. Is there a single function for it?