View source: R/shuffle_two_groups.R
shuffle_two_groups | R Documentation |
Shuffles data for use in two-group simulations.
shuffle_two_groups(d, groups)
d |
A data frame that contains the |
groups |
The name of the variable (in quotes!) that identifies which group each observation belongs to |
The original data frame with the group labels randomly shuffled among observations
# Make a data frame to shuffle og_data <- data.frame( "group" = c(rep("Group A", 600), rep("Group B", 200)), "result" = c(rep("Failure", 402), rep("Success", 198), rep("Failure", 120), rep("Success", 80)), stringsAsFactors = TRUE) # Tabulate successes & failures in each group in original data table(og_data$result, og_data$group) # Shuffle data with shuffle_two_groups shuffle_data <- shuffle_two_groups(og_data, "group") # Tabulate successes & failures in each group in shuffled data table(shuffle_data$result, shuffle_data$group)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.