Skip to contents

Random sampling with equal probability.

Usage

Unif(N, n, seed = NULL, replace = TRUE)

Arguments

N

Total sample size.

n

Subsample size.

seed

Random seed which is an integer (default NULL). This random seed is only valid for this sampling and will not affect the external environment

replace

A boolean.

  • TRUE (the default): Sampling with replace.

  • FALSE: Sampling without replace

Value

A numeric vector with length n which represent the subsample index.

Examples

N <- 1000
n <- 10
Unif(N = 1000, n = 10)
#>  [1] 590  33 384 110 999 855 655 870 342  20
Unif(N = 1000, n = 10)
#>  [1] 965 491  32 132  81 560 550 671 590 644
Unif(N = 1000, n = 10) != Unif(N = 1000, n = 10)
#>  [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE

Unif(N = 1000, n = 10, seed = 1)
#>  [1] 836 679 129 930 509 471 299 270 978 187
Unif(N = 1000, n = 10, seed = 123)
#>  [1] 415 463 179 526 195 938 818 118 299 229

Unif(N = 1000, n = 10, seed = 123, replace = TRUE)
#>  [1] 415 463 179 526 195 938 818 118 299 229
Unif(N = 1000, n = 10, seed = 123, replace = FALSE)
#>  [1] 415 463 179 526 195 938 818 118 299 229