sample(x = 1:10, size = 4, replace = F)#> [1] 6 9 3 5
The function sample() is used to generate random values from a vector, and it has the following arguments:
x size replace TRUE or FALSE
prob x
sample(x = 1:10, size = 4, replace = F)#> [1] 6 9 3 5
Select 10 numbers from 0 to 100
sample(x = 0:100, size = 10, replace = F) # replace=FALSE#> [1] 42 71 52 59 80 92 20 78 94 88
sample(x = 0:100, size = 10, replace = T) # replace=TRUE#> [1] 96 36 59 93 22 1 70 97 84 49
sample(replace = TRUE, x = LETTERS[1:4], size = 10)#> [1] "B" "C" "A" "A" "B" "A" "D" "D" "C" "D"
rbinom() and rnorm
rbinom() is used to draw a sample from a binomial distribution
size
prob
n
Draw a sample of size 8 from
rbinom(size = 10, prob = .75, n = 8)#> [1] 9 8 8 6 8 7 9 7
rnorm() is used to draw a sample from a normal distribution
mean
sd
n
Draw a sample of size 5 from
rnorm(mean = 10, sd = 4, n = 5)#> [1] 14.743527 8.970948 11.748854 8.539669 11.986696
pnorm()For
dnorm()dbinom(x = 5, size = 10, prob = 0.5)#> [1] 0.2460938
qnorm()qnorm(p = 0.975, mean = 0, sd = 1)#> [1] 1.959964