I think you answered your own question. For loops are not a boogeyman... poor memory management is.
Algorithms that are sensitive to evaluation sequence are often not very re-usable, and certainly not parallelizable. If you have a specific algorithm in mind, there may be some advice we can give you about optimization, but as it stands think you know how to get a working implementation. -- Sent from my phone. Please excuse my brevity. On November 10, 2016 5:06:07 AM PST, Thomas Chesney <thomas.ches...@nottingham.ac.uk> wrote: >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)){ > >} > >but > >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, > >Thomas >http://www.nottingham.ac.uk/~liztc/Personal/index.html > > > >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. > >______________________________________________ >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >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. ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.