Reputation: 11
How do I randomly assign a group of people into four treatment groups and a control group, given that I have a list of their names on an excel document?
Upvotes: 1
Views: 5654
Reputation: 2252
Get the randomizr package
install.packages("randomizr")
library(randomizr)
use complete random assignment (holds the number of units assigned to each condition fixed across randomizations, unlike sample
with replace = TRUE
Z <- complete_ra(N = 100, num_arms = 5)
table(Z)
Upvotes: 4
Reputation: 3947
If you have 100 names (number them as such) then you can assign them to one of 5 groups with
split(1:100, sample(1:5, 100, replace = TRUE))
split(x, f)
splits x
into groups according to f
, for which I've used sample
to sample 100 occurrences of the numbers 1 to 5 (with replacement).
Take these numbered names from your list.
(Note: you didn't specify equal groups).
Alternatively, the caret
package can handle this quite nicely for you: https://topepo.github.io/caret/data-splitting.html
Upvotes: 1