complete_rs implements a random sampling procedure in which fixed numbers of units are sampled. The canonical example of complete random sampling is a procedure in which exactly n of N units are sampled. Users can set the exact number of units to sample with n. Alternatively, users can specify the probability of being sampled with prob and complete_rs will infer the correct number of units to sample. complete_rs will either sample floor(N*prob) or ceiling(N*prob) units, choosing between these two values to ensure that the overall probability of being sampled is exactly prob. Users should specify N and not more than one of n or prob. If only N is specified, N/2 units will be sampled. If N is odd, either floor(N/2) units or ceiling(N/2) units will be sampled.

complete_rs(N, n = NULL, prob = NULL, check_inputs = TRUE)



The number of units. N must be a positive integer. (required)


Use for a design in which exactly n units are sampled. (optional)


Use for a design in which either floor(N*prob) or ceiling(N*prob) units are sampled. The probability of being sampled is exactly prob because with probability 1-prob, floor(N*prob) units will be sampled and with probability prob, ceiling(N*prob) units will be sampled. prob must be a real number between 0 and 1 inclusive. (optional)


logical. Defaults to TRUE.


A numeric vector of length N that indicates if a unit is sampled (1) or not (0).


S <- complete_rs(N = 100) table(S)
#> S #> 0 1 #> 50 50
S <- complete_rs(N = 100, n = 50) table(S)
#> S #> 0 1 #> 50 50
S <- complete_rs(N = 100, prob = .111) table(S)
#> S #> 0 1 #> 89 11
# If N = n, sample with 100% probability... complete_ra(N=2, n=2)
#> [1] T1 T2 #> Levels: T1 T2
# except if N = n = 1, in which case sample with 50% probability complete_ra(N=1, n=1)
#> [1] T1 #> Levels: T1