[R] Incrementing a counter in lapply

Thomas Lumley tlumley at u.washington.edu
Tue Mar 14 18:30:46 CET 2006


On Tue, 14 Mar 2006, Gabor Grothendieck wrote:

> On 3/14/06, Thomas Lumley <tlumley at u.washington.edu> wrote:
>> On Tue, 14 Mar 2006, Gabor Grothendieck wrote:
>>
>>> On 3/14/06, Thomas Lumley <tlumley at u.washington.edu> wrote:
>>>> It is probably worth pointing out here that the R documentation does not
>>>> specify the order in which lapply() does the computation.
>>>>
>>>
>>> I suspect that a huge amount of application code takes advantage
>>> of this order.
>>>
>>
>> I don't.  The order of evaluation is usually not readily observable. You
>> either have to use <<- to modify an external variable or you have to
>> produce printed or graphical output where the order matters.
>>
>> There's probably some examples, but there are some examples of people
>> using solve(t(X) %*% W %*% X) %*% W %*% Y to compute regression
>> coefficients, too.
>
> By order do you mean that the result is returned in a random order
> or that the result is returned in a fixed order but computed it a random
> order?
>

It is returned in a fixed order, the first output corresponding to the 
first input.  The documentation does not specify what order it is 
*computed* in.

This in contrast to eapply(), which returns the results in a random order.

 	-thomas

Thomas Lumley			Assoc. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle




More information about the R-help mailing list