Created
February 22, 2022 20:04
-
-
Save grosscol/015af36e5bc55c171d0a799cf2cfa8ba to your computer and use it in GitHub Desktop.
Simple Group Assignments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Author: Colin Gross | |
# Date: 2022-02-22 | |
#' Simple group assignments. | |
#' Randomly order equally distributed group ids | |
#' @param num_groups Number of study groups | |
#' @param num_per_group Number of individuals per group. | |
#' @return named vector of randomly selected group assignments. | |
simple_grp_assignments <- function(num_groups, num_per_group){ | |
num_indv <- num_groups * num_per_group | |
grp_labels <- LETTERS[1:num_groups] | |
grp_ids <- rep(grp_labels, num_per_group) | |
grp_assignments <- sample(grp_ids, size = num_indv, replace=FALSE) | |
names(grp_assignments) <- 1:length(grp_assignments) | |
return(grp_assignments) | |
} | |
assignments <- simple_grp_assignments(3, 5) | |
checksum <- digest::sha1(assignments) | |
cat("assignments:\n") | |
print(assignments) | |
cat(paste("\nassignments checksum:", checksum, "\n")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment