Last active
August 29, 2015 14:14
-
-
Save btskinner/c755008fa7a514824dd7 to your computer and use it in GitHub Desktop.
R code to create randomized seating assignment
This file contains 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
################################################################################ | |
## | |
## Seating Assignment Randomizer | |
## Benjamin Skinner | |
## | |
################################################################################ | |
## This file randomizes seating assignment. It assumes that people are | |
## assigned to their seats sequentially: first through the door, first | |
## seat; second through the door, second seat...and so on. Every table | |
## will have a person assigned before a table gets another person. At | |
## worst, there will only be a one person difference in the number of | |
## people at each table. | |
## The purpose is to prevent groups of people who come in together from | |
## sitting together. Good for events without predefined seating | |
## assignments that want people to sit with new people. | |
## assign values: total number of tables; total seats per table | |
tables <- 10 # input value | |
seats <- 5 # input value | |
## init assignment vector; assign seats (all tables before next seat) | |
assign <- c() | |
for(r in 1:seats){ | |
r <- sample(seq(1,tables,1)) | |
assign <- c(assign, r) | |
} | |
## put vector into matrix; add colnames (Rounds); print | |
assign <- matrix(assign, ncol = seats) | |
colnames(assign) <- paste0('R', seq(1,seats,1)) | |
print(assign) | |
## write table to txt file (adding spacer row) | |
write.table(rbind(rep('-', seats), assign), 'assign.txt', sep = '\t', | |
row.names = F, quote = F) | |
## To use: work through each column, from top to bottom, before moving to the | |
## next column. | |
## ----------------------------------------------------------------------------- | |
## END FILE | |
## ============================================================================= |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment