Skip to content

Instantly share code, notes, and snippets.

@chelseaparlett
Last active August 6, 2019 16:33
Show Gist options
  • Save chelseaparlett/a787d9e742128f9a2c65c437a47ae35e to your computer and use it in GitHub Desktop.
Save chelseaparlett/a787d9e742128f9a2c65c437a47ae35e to your computer and use it in GitHub Desktop.
getRandSamples <- function(seed = NA){
if (!is.na(seed)){
set.seed(seed) #incase you need repeatable data generation.
#but remember to set a different seed for each person if you want them to get different items at each time point.
}
True_New <- sample(1:20,20,replace = F) #items that are true + new
True_Rep <- sample(21:40,20,replace = F) #items that are true + repeated
False_New <- sample(41:60,20,replace = F) #items that are false + new
False_Rep <-sample(61:80,20,replace = F) # items that are false + repeated
items <- list(True_New, True_Rep, False_New, False_Rep)
t1 <- sapply(items, function(x) x[1:5]) #items to give at time 1
t2 <- sapply(items, function(x) x[6:10]) #items to give at time 2
t3 <- sapply(items, function(x) x[11:15]) #items to give at time 3
t4 <- sapply(items, function(x) x[16:20]) #items to give at time 4
#return dataframe with time and items for each time point
return(data.frame(time = sort(rep(0:3,20)),
item = c(t1,t2,t3,t4)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment