when vectorising does not work: silent function fail?
Also, you probably get less data copying by using a for() or while() loop than by using apply() in this context.
Why may there be less data copying with "for" and "while" compared to apply?
Finally, the overhead of formula parsing and model matrix construction repeated thousands of times probably dominates this computation; if it isn't just a one-off it would probably be worth a lower-level implementation.
Does "lower-level implementation" mean code this outside of R. Thanks! Juliet