Hi,

I'm trying to randomize a sequence of trials for an experimental design. The trials consist of values for each of two factors. As is there are 30 combinations of the two factors, and I want them to be ordered randomly but with the requirement that for one of the factors, the value can never be the same as the previous value.

I'm currently randomizing my dataframe by using:

 x[sample(1:nrow(x), nrow(x),]

Output example, on rows 2 and 3 the angle value is the same (the situation I wish to prevent):
   Distance Angle
        9    90
        9    45
       10   45
       11   30
        8    60
        7     0
        8    30
       10     0
       10    60
        ...    ...

Can anyone recommend a simple way to do this? (Bonus if it could be implemented for more than a single column!)

Thanks in advance,

Jon
--
Jon Zadra
Department of Psychology
University of Virginia
P.O. Box 400400
Charlottesville VA 22904
(434) 982-4744
email: za...@virginia.edu
<http://www.google.com/calendar/embed?src=jzadra%40gmail.com>

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to