## Randomization for a single patient
sample(c("T", "C"), size=1)[1] "T"
## Randomize 20 independent patients
(patients <- sample(c("T", "c"), size=20, replace=TRUE)) [1] "T" "T" "T" "T" "c" "T" "T" "c" "T" "c" "T" "T" "T" "c" "c" "c" "c" "c" "T"
[20] "c"
## How many patients are assigned to treatment group?
sum(patients == "T")[1] 11
## Simulate by repeating 10000 times
Ntreat <- replicate(10000, {
patients <- sample(c("T", "C"), size=20, replace=TRUE)
sum(patients == "T")
})
