Should the “while loop” be preferable to “for loops” for large, needed loops in R?

Understanding that loops are usually not ideal in R, sometimes they are necessary.

When writing large loops, do not

for (i in 1:large_number) 

so how should a large_number size vector be created?

Will this be done when loops are the best choice for large, needed loops?

+6
loops for-loop r while-loop
source share
1 answer

Firstly, many of these “loops are bad” chatter from dark eras, when loops that are actually less effectively implemented, in particular, in some versions of S-Plus.

However, and if your comment on the need for a large index object is correct, you can also use

As an added bonus, options 1 and 2 provide a way to run loops in parallel on suitable systems using tools from the CRAN snow, multi-core, or NWS packages, to name a few.

+12
source share

All Articles