vendredi 9 novembre 2018

How do I correctly randomize this specific data?

I would like to randomize Tests and the order of their versions. My data should look like this in the end:

> #  subject    Test     t1 t2 t3 t4
> # 1      1    PFT      A  B  C  D
> # 2      1    AWT      B  C  D  A
> # 3      1    BWFT     (...)
> # 4      1    AUT
> # 5      1    DPD-WN
> # 6      1    DPT-NI
> # 7      2    AWT
> # (...)  250

I have found something that helps me partly:

seed <- 42 blocksize <- 6 N <- 250 x 6

set.seed(seed) subject = rep(1:ceiling(N/blocksize), each = blocksize)

a1 = data.frame(subject, rand=runif(length(subject)), envelope= 1: length(subject)) a2 = a1[order(a1$subject,a1$rand),]

a2$Test = rep(c("BWFT", "DPT-NI", "DPD-WN", "AUT", "PFT", "AWT"), times = length(subject)/6) assign = a2[order(a2$envelope),] head(assign,12)

Can you please help me with the rest? Thank you kindly!




Aucun commentaire:

Enregistrer un commentaire