我面临着一个特殊的情况,我的班上有31个学生,我想把他们分成8个小组(每个小组4个,只有一个人只有3个人除外).我试图遵循的具体规则是,如果其他学生已经合作过,任何学生都不能与其他学生合作.
我需要创建三个组集合(即每次包括8个组)三个星期,并遵循这个逻辑.手动这是一个有点复杂,我希望我可以写一个代码在R中得到想要的结果,但我不知道如何纠正以下,因为它没有给我在某些情况下的写入顺序.
# List of student names
students <- c("Student1", "Student2", "Student3", "Student4", "Student5", "Student6", "Student7", "Student8", "Student9", "Student10",
"Student11", "Student12", "Student13", "Student14", "Student15", "Student16", "Student17", "Student18", "Student19", "Student20",
"Student21", "Student22", "Student23", "Student24", "Student25", "Student26", "Student27", "Student28", "Student29", "Student30", "Student31")
# Number of students
num_students <- length(students)
# Number of rounds
num_rounds <- 3
# Group size
group_size <- 4
# Create an empty list to store groups
all_groups <- list()
# Function to create groups
create_groups <- function(students, group_size) {
shuffled_students <- sample(students)
groups <- split(shuffled_students, ceiling(seq_along(shuffled_students)/group_size))
return(groups)
}
# Loop through each round
for (round in 1:num_rounds) {
# Create groups for the current round
groups <- create_groups(students, group_size)
# Append the groups to the list
all_groups[[paste0("Round", round)]] <- groups
}
# Print the results
for (round in 1:num_rounds) {
cat("Round", round, ":\n")
print(all_groups[[paste0("Round", round)]])
cat("\n")
}
一旦找到了正确的序列,有没有办法知道这是否奏效?
谢谢你的帮忙!