Last active
February 2, 2018 19:59
-
-
Save davebraze/eb0d8bf8f1c68301bc449ea58e0bf1b2 to your computer and use it in GitHub Desktop.
Block randomize a stimulus list with dplyr
This file contains hidden or 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
library(dplyr) | |
## Toy data | |
df <- data_frame(block=rep(1:3, each=4), item=rep(1:4,3), | |
cond=rep(LETTERS[1:2], 6), | |
stim=paste0(rep(letters[1:2],6), rep(1:6,each=2))) | |
## Randomize blocks and trials within blocks | |
df.rand <- df %>% | |
group_by(block) %>% | |
mutate(item = sample(item)) %>% | |
ungroup %>% | |
mutate(block = rep(sample(1:3), each=4)) %>% | |
arrange(block,item) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment