[R] Vectorization in a random order

Thomas Chesney Thomas.Chesney at nottingham.ac.uk
Thu Nov 10 14:06:07 CET 2016

Is there a way to use vectorization where the elements are evaluated in a random order?

For instance, if the code is to be run on each row in a matrix of length nBuy the following will do the job

for (b in sample(1:nBuy,nBuy, replace=FALSE)){



apply(nBuyMat, 1, function(x))

will be run I believe, in the same order each time (Row1, then Row2, then Row3 etc.)

This is important for building agent based models (the classic explanation of this is probably Huberman & Glance's response to Nowak & May's 1992 Nature article - Evolutionary games and computer simulations, http://www.pnas.org/content/90/16/7716.abstract)

Thank you,


This message and any attachment are intended solely for the addressee
and may contain confidential information. If you have received this
message in error, please send it back to me, and immediately delete it. 

Please do not use, copy or disclose the information contained in this
message or in any attachment.  Any views or opinions expressed by the
author of this email do not necessarily reflect the views of the
University of Nottingham.

This message has been checked for viruses but the contents of an
attachment may still contain software viruses which could damage your
computer system, you are advised to perform your own checks. Email
communications with the University of Nottingham may be monitored as
permitted by UK legislation.

More information about the R-help mailing list