I am really not sure if there is a technical term for what I am trying to do so I'll try to be as clear as possible.
I currently have 18 tables of 2x9 = 18 cells. These are token sets I am going to use in an experiment.
Each of these tables is characterized by a different linguistic context, especially a different main verb. For example here are my first two tables:
... and so on 18 times in total.
What I'd like to do is to "shuffle" these tables so that each table contains one of each condition in the 18 original conditions, and where no condition is repeated twice.
For instance, cell 1 would have "you'll can enjoy...", cell 2 will have "he'd could climb...", and so on in the first table, and the second table would move these contexts down one cell.
I'm not sure how to do this automatically (it is quite a pain to do by hand). Is there any way to do this in R?
Crucially I'm not trying to randomize. There is an ordered way in which the tables are shuffled.
All the best,
Cameron
So first I recreated your tables, using base R's sentences object to simulate each cell:
start_index <- seq(1,18*18,18)
end_index <- seq(18,18*18,18)
for (i in 1:18){
tables[[i]] <- sentences[start_index[i]:end_index[i]]
}
Then wrote a function to loop through them, using the table index as the argument:
tablemaker <- function(n){
new_table <- list()
for (i in 1:18){
new_table[i] <- tables[[ifelse(n-1+i > 18,n-1+i-18 ,n-1+i)]][i]
}
return(new_table)
}
After that, we can map them:
new_tables <- purrr::map(1:18, tablemaker)
And then check to make sure all the cells are still unique:
> 18*18
[1] 324
> length(unique(unlist(new_tables)))
[1] 324
> length(unique(unlist(tables)))
[1] 324