Question

I have to assign articles to various coders. Each article should be coded twice and no pair of coders can exclusively work together.

I figured that the scheme should look like this (test is an illustration of what I need):

art_id <- 1:21
coder1 <- c(1,2,3,4,5,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
coder2 <- c(1,0,0,0,0,0,7,8,9,10,11,0,0,0,0,0,0,0,0,0,0)
coder3 <- c(0,2,0,0,0,0,0,0,0,0,0,12,13,14,15,0,0,0,0,0,0)
coder4 <- c(0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,16,17,18,0,0,0)
coder5 <- c(0,0,0,4,0,0,0,0,9,0,0,0,13,0,0,16,0,0,19,20,0)
coder6 <- c(0,0,0,0,5,0,0,0,0,10,0,0,0,14,0,0,17,0,19,0,21)
coder7 <- c(0,0,0,0,0,6,0,0,0,0,11,0,0,0,15,0,0,18,0,20,21)

test <- data.frame(art_id, coder1, coder2, coder3, coder4, coder5, coder6, coder7)

This clearly is possible in an easier way, but my math-skills are pretty limited. Is there an "easy" way to assign 200 articles automatically in this way? Note that art_id will be characters and not numbers like in this illustration.

Thanks.

Était-ce utile?

La solution

I agree with Carl Witthoft's advice and and would recommend you to use the combn function.

Here is my try:

# Setup articles
articles <- paste("article_", seq(1:200))

# Setup unique coder probabilities 
coders <- paste0("coder_", seq(1:7))
unique.coder.combinations <- do.call(paste, c(data.frame(t(combn(coders, 2)))))

# Assignment
coder.selection <- cbind(articles, coders=sample(unique.coder.combinations, 200, replace=TRUE))

# head(coder.selection)
# > head(coder.selection)
#      articles     coders           
# [1,] "article_ 1" "coder_1 coder_5"
# [2,] "article_ 2" "coder_2 coder_4"
# [3,] "article_ 3" "coder_4 coder_6"
# [4,] "article_ 4" "coder_3 coder_7"
# [5,] "article_ 5" "coder_5 coder_7"
# [6,] "article_ 6" "coder_3 coder_4"

Autres conseils

Not certain, but I think going in a different direction will do it. First calculate all possible "coder pairings".

codepair <- combn(1:7,2)

Then randomly assign your art_id values to the columns in codepair

Note that you need a certain minimum number of coders for a given number of objects.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top