Skip to content

Instantly share code, notes, and snippets.

@explodecomputer
Last active April 28, 2016 09:45
Show Gist options
  • Save explodecomputer/298d875cc64f40eef2f1e02b6215c490 to your computer and use it in GitHub Desktop.
Save explodecomputer/298d875cc64f40eef2f1e02b6215c490 to your computer and use it in GitHub Desktop.
ProgOne pairings
library(reshape2)
get_pairs <- function(people)
{
require(reshape2)
# Create matrix of all possible pairings
# Only use pairings on diagonal with an offset of half the number of people
# This ensures that there is equal spacing between each person's turn to present (as def or pros)
p <- rep(people, 2)
x <- matrix(0, length(p), length(p))
rownames(x) <- p
colnames(x) <- p
# Get offset coordinates
n <- round(length(people)/2)+1
n1 <- n:ncol(x)
x[cbind(seq(n1), n1)] <- 1
# Get pairings
dat <- subset(melt(x), value==1)[1:length(people),1:2]
names(dat) <- c("defendant", "prosecutor")
rownames(dat) <- NULL
return(dat)
}
set.seed(100)
people <- c("gib", "david", "jack", "hannah", "neil", "lavinia", "luisa", "eleanor", "evie")
# Get pairings using get_pairs
# For each round shuffle the order of the people so that the pairings are different
rounds <- 3
l <- list()
for(i in 1:rounds)
{
l[[i]] <- get_pairs(sample(people))
}
dat <- do.call(rbind, l)
write.csv(dat, file="pairs.csv")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment