I want to select different samples based on this :
dat<- rnorm(5000, mean = 100, sd = 10)
Next, I want to select different samples to get quintile (QU)= 0.60 for each data set Here is the outcome of interest:
SS QU
5 x
10 x
15 x
25 x
50 x
75 x
100 x
250 x
500 x
750 x
1000 x
1250 x
1500 x
2000 x
2500 x
3000 x
3500 x
4000 x
4500 x
5000 x
I have failed to get it using the following codes
sapply(c(5, 10, 15, 25, 50, 75, 100, 250, 500, 750, 1000, 1250, 1500, 2000, 2500, 3000, 3500, 4000, 4500, 5000), function(x) {
x1 <- sample(dat$dat, x, replace = TRUE)
c(unname(quantile(x1 , .60)))
CodePudding user response:
We may need
SS <- c(5, 10, 15, 25, 50, 75, 100, 250, 500, 750, 1000, 1250, 1500, 2000, 2500, 3000, 3500, 4000, 4500, 5000)
QU <- sapply(SS, function(x) {
x1 <- sample(dat, x, replace = TRUE)
unname(quantile(x1, .60))
})
data.frame(SS, QU)
-output
SS QU
1 5 107.8017
2 10 101.2228
3 15 101.6636
4 25 103.1269
5 50 101.7254
6 75 102.4818
7 100 104.6631
8 250 103.1844
9 500 102.4056
10 750 102.5745
11 1000 102.8261
12 1250 103.0092
13 1500 102.5766
14 2000 102.7607
15 2500 102.6239
16 3000 102.2122
17 3500 102.6231
18 4000 102.7531
19 4500 102.6493
20 5000 102.5840